2 registered members (firecrest, AndrewAMD),
387
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Multiple assets with options
[Re: GreenBoat]
#466443
06/14/17 12:48
06/14/17 12:48
|
Joined: Nov 2016
Posts: 66
GreenBoat
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2016
Posts: 66
|
The script is as simple as possible:
void run() {
set(PRELOAD|LOGFILE);
BarPeriod = 1440;
BarZone = ET;
BarOffset = 15*60;
StartDate = 20130101;
EndDate = 20151231;
PlotWidth = 1000;
PlotHeight1 = 400;
Multiplier = 100;
assetList("Assets");
if(is(FIRSTINITRUN)) {
asset("SPY");
dataLoad(1,"SPY_Options.t8",9);
asset("YHOO");
dataLoad(2,"YHOO_OptionsSim.t8",9);
}
string assetName;
while (assetName = loop(Assets)) {
asset(assetName);
if (assetName == "SPY") contractUpdate(assetName,1,CALL|PUT);
else if (assetName == "YHOO") contractUpdate(assetName,2,CALL|PUT);
var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl); // the current underlying price (unadjusted)
CONTRACT* c = contract(PUT|ONLYW3,30,CurrentPrice);
if(contractDays(c) == 31 /*&& assetName == "YHOO"*/) enterShort();
}
}
|
|
|
Re: Multiple assets with options
[Re: jcl]
#466483
06/16/17 14:43
06/16/17 14:43
|
Joined: Nov 2016
Posts: 66
GreenBoat
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2016
Posts: 66
|
The script is working! Your answer helped me, thank you. Another thing is, that I was getting "Crash in the script error", only once, at the first day after the lookback period. After debugging, I found that: - the error is there only when I use SPY data (from IVolatility) - the error is not there when I use artificial historical data generated by financial-hacker script - the error is caused by Contracts->fUnl - the error is there when the code looks like this:
while (assetName = loop(Assets)) {
if (assetName == "SPY") contractUpdate(assetName,1,CALL|PUT);
else if (assetName == "YHOO") contractUpdate(assetName,2,CALL|PUT);
asset(assetName);
var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl);
......
when I select the asset before contractUpdate, there is no Crash in the script. My code without errors is:
while (assetName = loop(Assets)) {
asset(assetName);
if (assetName == "SPY") contractUpdate(assetName,1,CALL|PUT);
else if (assetName == "YHOO") contractUpdate(assetName,2,CALL|PUT);
var CurrentPrice = ifelse(is(TRADEMODE),priceClose(),Contracts->fUnl);
|
|
|
Re: Multiple assets with options
[Re: jcl]
#466486
06/16/17 15:50
06/16/17 15:50
|
Joined: Nov 2016
Posts: 66
GreenBoat
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2016
Posts: 66
|
I forget to mention, that I have only two assets in the assets file:
Name,Price,Spread,RollLong,RollShort,PIP,PIPCost,MarginCost,Leverage,LotAmount,Commission,Symbol SPY,215,0.02,0,0,0.01,0.01,0,4,1,0.02, YHOO,215,0.02,0,0,0.01,0.01,0,4,1,0.02,
The second version of the code doesn't crash. Only the first version of the code causes crash, which is the version where asset(assetName) is after contractUpdate. And it crashes only once, one day after lookback period.
|
|
|
|