Basic Time Windowed profit taking

Posted By: TimExcellent

Basic Time Windowed profit taking - 11/27/21 03:19

Hi I'm not a coder at all, but have learnt/hacked some basics and bodged something together myself today, I'm working with a developer on this for a complete trading strategy and trying to adapt a script I found that I got running (all by myself!) for a basic backtest to figure out some thresholds for myself - trying to be more useful! (currently it trades far too much - which was the purpose of the script from Robot Wealth course I'm doing, but it has the bare bones of what I'm trying to at least just test and then export different thresholds to an excel sheet where I'll do the rest of my data work)

So I downloaded raw SPX Tick and 1 minute data (the strategy is intraday) which I have successfully saved as .t6 format from my broker, so initial parameters look like this:

// Simulation parameters
setf(PlotMode, PL_FINE);
set(PLOTNOW);
BarPeriod = 15;
StartDate = 20210105;
EndDate = 20210130;
History = "*.t6";
LookBack = 20/BarPeriod*6.5;
assetList("AssetsTS");
asset("SPX");
MaxLong = MaxShort = 1;
//

I then parse the .t6 data through a static var function to build up bars to calculate volatility vars vol = series(sqrt(Moment(returns, 20/BarPeriod*6.5, 2))), then I have a stdev threshold for entry. But I then want to take the derived data from my stored parameters and then enter into an option contract which is a .t8 format - how do I do that, do I need to define another function that addresses the Options data I have?

So I'm calculating from the Underlying Price data and then wanting to trade the derivative contract/options.

I then need to add a second piece of trade logic snippet to take the entry signal (eg. 2.0 stdevs) and then tell Zorro to look for .t8 files in History folder:

1. Will Zorro know to also check the same Start and End Date as the Simulation parameters above, or do I need to define a Start End Date function that both the Price series and Options series would look at seperately?
2. Does anyone have a basic Long Straddle code snippet they could share? I'm having trouble unpicking other examples I've found of options strategies, it is just for an ATM Straddle when the threshold Stdev's are met.
3. Any tips on how to create and store "At The Money" price series to enter the straddle? I dont think I even have to really, as I just want to enter a Long Put and a Long Call at the exact stdev condition being met at this point, so really its just trade the closest strike
4. Is there an export data to excel/csv function?

Thanks
Posted By: Petra

Re: Basic Time Windowed profit taking - 11/27/21 11:18

Call contractUpdate at any bar in the backtest, then the contract function to find the at the money contracts.

There are some script examples for options trading.

For exporting data to csv you can use print(TO_CSV,...) or dataSaveCSV.
Posted By: TimExcellent

Re: Basic Time Windowed profit taking - 11/28/21 00:16

Thanks Petra, is defining DTE 0 or the contract look up being days to expiry 0 enough for zorro to know to look for contracts expiring that day, or would I need to specifically give it a fractional time based expiry window?

Also I noticed in the contract.c file that the calculations use 365.25 days, usually I think traders in pricing models use 252 days which is the number of trading days roughly in a year - is there a good reason to stick with 365 days in the calculations there that you have found or just havent been asked?
Posted By: Petra

Re: Basic Time Windowed profit taking - 11/28/21 07:38

DTE is always in calendar days. For expiring same day, use DTE 0 or the current date in yyyymmdd format.
© 2024 lite-C Forums