Un piccolo contributo alla discussione
(ho lasciato tutte le dichiarazioni di variabili, anche quelle non necessarie)
1.aggiungere 5 optioni call e 5 put piu atm alla strategia alle 9:40.
uses classes
dim z
dim controllo
dim atmstrike
dim under as tsecurity
dim price
dim underisin
dim atmvola
dim atmexp
dim nextexp,nextexpma,nextexpanno,nextexpnc ,j,i
dim atmcall as toption
dim calls as toption = [0,0,0,0,0]
dim puts as toption = [0,0,0,0,0]
dim sommaevolacalls as single = 0
dim sommaevolaputs as single = 0
dim sommavolacalls as single = 0
dim sommavolaputs as single = 0
dim a as double
dim strikestep, strikeas
dim ore as Word, minuti as Word, secondi as Word, usec as Word
dim volacallbs, volaputbs
dim pricea As Double, delta As Double, gamma As Double,
theta As Double, vega As Double, rho As Double,
timeValue As Double, implVolatility As Double
dim diffvola
dim count = 0
dim ciao as tstringlist = [0,0,0,0,0,0,0,0]
dim file as tstringlist
dim percorso as string
dim anno, mese, giorno
under = CurrentStrategy.GetMainUnderlying
price = CurrentStrategy.GetMainUnderlyingprice
underisin = under.isin
count = CurrentStrategy.GetOptionCount
file = new TStringList()
strikestep = GetNextStrike(underisin,price) - GetPreviousStrike(underisin,price)
'strikestep = intervallo tra strike
atmstrike = GetNearestStrike(underisin, price)
nextexp = CDate(GetNextExpiry(underisin, now()))
if mid(nextexp,2,1)= "/" then
nextexp = "0" + left(nextexp,9)
else
nextexp = left(nextexp,10)
end if
'nextexp format mm/gg/aaaa
nextexpma = left(nextexp,2) + "-" + right(nextexp,4)
'nextexpma format mm-aaaa
DecodeTime(Now(), ore, minuti, secondi, usec)
DecodeDate(Now(), anno, mese, giorno)
if ore = 9 and minuti<40 then
SetPersistentVar(controllo,1)
else
SetPersistentVar(controllo,0)
end if
if controllo = 1 then
CurrentStrategy.DisableOptionExpiry(nextexp)
file.SaveToFile(percorso)
for i=0 to 4 step 1
CurrentStrategy.AddParametricOption(underisin,CALL,i-2,0)
CurrentStrategy.AddParametricOption(underisin,PUT,i-2,0)
next
end if
'assegnare le opzioni aggiunte a variabili array:
'nota : getstrikebyindex mi sembra che non funzioni
for i = 0 to 4
strikeas = cstr(atmstrike + (i-2)*strikestep)
calls[i] = CurrentStrategy.GetByName("C @ "+strikeas+" "+nextexpma)
puts[i] = CurrentStrategy.GetByName("P @ "+strikeas+" "+nextexpma)
next
2. scrive valore su file
price = CurrentStrategy.GetMainUnderlyingprice
z = CStr(giorno)
file.LoadFromFile(percorso)
file.add(price & " ciao " )
file.SaveToFile(percorso)
file.free