npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

options-strategy-builder

v1.0.6

Published

### We support Nifty and Banknifty Options backtesting from Jan 2019 in 5 minute time frame. --- ## Quickstart

Downloads

11

Readme

Options Strategy Builder

We support Nifty and Banknifty Options backtesting from Jan 2019 in 5 minute time frame.


Quickstart

1. Install

    npm install options-strategy-builder

2. Require module

    const builder = require("options-strategy-builder")

3. Run the module

await builder(timings={open:{daysToExpiry:1,hour:15,min:30},close:{daysToExpiry:0,hour:9,min:20}},script,tradeFunction,options,intermediateCallbackFunction)

Where

  • timings is a configuration storing trade open and close times
  • script is the script you want to backtest on. For now we support "NIFTY" and "BANKNIFTY" as valid script value
  • options additional control parameters if needed
  • tradeFunction is the function which will define all the trade decisions taken within a trade
  • intermediateCallbackFunction is the function sends update as the backtesting is being performed

4. Define tradeFunction

const tradeFunction = async(currentTradeData, ocData, context)=>{ 
    let orders=[]
    //WRITE YOUR OWN LOGIC// 
    return {orders,context}
}

Where

  • currentTradeData is the currentTradeData with pnl and leg position.
  • ocData is the option chain data of that particular timestamp
  • context is the data which can be used as wished. It is a optional recurrent data which is maintained during a trade session.

tradeFunction Inputs

currentTradeData

    { 
         bookedPnl:number (Float),
         pnl:number (Float),
         legs:{
             <strikePrice>:{
                 call:[{
                    ltp:number (Float),
                    quantity:number (Integer eg. 1,2),
                    opType:<BUY/SELL>
                 },...],
                 put:[{
                    ltp:number (Float),
                    quantity:number (Integer eg. 1,2),
                    opType:<BUY/SELL>
                 },...]
             }
         }
     }

ocData

    {
         currentTimestamp:number (Timestamp in millis),
         expiryTimestamp:number (Timestamp in millis),
         daysToExpiry:number (Integer eg. 1,2),
         volatility:number (Float),
         lotSize:number (Integer eg. 50),
         futurePrice:number (Float),
         spotPrice:number (Float),
         strikeAtm:number (Integer eg. 17800,18000),
         strikeDiff:number (Integer eg. 50),
         optionChainData:{
                 <strikePrice>:{
                             call :{
                                 ltp:number (Float), 
                                 strike:number (Integer eg. 17800,18000), 
                                 delta:number (Integer ranging from 0 to 100), 
                                 iv:number (Float)
                             },
                             put :{
                                 ltp:number (Float), 
                                 strike:number (Integer eg. 17800,18000),  
                                 delta:number (Integer ranging from 0 to 100),  
                                 iv:number (Float)
                             }
                     }
             }
     }

context

    {
        // The context is reset in every trade. Data in the context will only be modified by tradeFunction.
    }

tradeFunction Output

orders

    [{
        legType:<PUT/CALL>,
        opType:<BUY/SELL>,
        strike:<strike to be executed> (Integer eg. 17800,18000),
        quantity:<number of lots> (Integer eg. 1,2)
    },...]

context

    {
        // Put whatever contextual data you wish to use in a trade session. The context is reset in every trade.
    }

Example

const builder = require("options-strategy-builder")
//Example of BANKNIFTY Straddle at 9:20 am with full price sl on both legs
const tradeFunction = async(currentTradeData, ocData, context,timings,script,options)=>{
    let orders=[]
    const currentDate=new Date(ocData.currentTimestamp)
    if(!context.isEnd){
        if(currentDate.getHours()==9&&currentDate.getMinutes()==20){
            orders=[{legType:"PUT",opType:"SELL",strike:ocData.strikeAtm,quantity:1},{legType:"CALL",opType:"SELL",strike:ocData.strikeAtm,quantity:1}]
            context.strikeAtm=ocData.strikeAtm
            context.sl=ocData.optionChainData[ocData.strikeAtm].call.ltp+ocData.optionChainData[ocData.strikeAtm].put.ltp
        }
        else if(context.strikeAtm&&currentTradeData.legs[context.strikeAtm]&&currentTradeData.legs[context.strikeAtm].put.pnl<-context.sl){
            orders=[{legType:"PUT",opType:"BUY",strike:context.strikeAtm,quantity:1},{legType:"CALL",opType:"BUY",strike:context.strikeAtm,quantity:1}]
            context.isEnd=true
        }
        else if(context.strikeAtm&&currentTradeData.legs[context.strikeAtm]&&currentTradeData.legs[context.strikeAtm].call.pnl<-context.sl){
            orders=[{legType:"PUT",opType:"BUY",strike:context.strikeAtm,quantity:1},{legType:"CALL",opType:"BUY",strike:context.strikeAtm,quantity:1}]
            context.isEnd=true
            
        }
    }
    return {orders,context}
}


;(async()=>{
    try{
        const result=await builder({open:{daysToExpiry:0,hour:9,min:20},close:{daysToExpiry:0,hour:15,min:30}},"BANKNIFTY",tradeFunction,(updateData)=>{
            console.log(updateData)
        })
        console.log(result)
    }
    catch(e){
        console.log(e)
    }
    
})()