Wednesday, March 16, 2011

Python and Quant

I was looking for doing easier to stress my portfolios, I got to http://appropriatesoftware.net /quant/Documentation.html.... but, what a pity, it's not finished, it's not usable.

It's better to create my own library. And, to simulate my loan (in Swiss Francs) join with a call and a put, I would like to write a code like:


nov29 = CalUtils.createStrikeDate(29, 11, 2010)

portfolio = Portfolio()
market = Market()
# EURCHF - how many CHF to buy 1 EUR
op1 = EuropeanLongCall(0.01440, 1.3335, nov29, "EURCHF", 20000)
op2 = EuropeanShortCall(0.00220, 1.3615, nov29, "EURCHF", 200000)
# CHFEUR - how many EUR to buy 1 CHF
debt = Loan(nov29, "CHFEUR", 1300)

portfolio.add(op1)
portfolio.add(op2)
portfolio.add(debt)


# Simulation
print "EURCHF", ",", "Payoff", ",", "Loan"
for a in xrange((1.3800 - 1.3280) / 0.0001):
x = a * 0.0001 + 1.3280;
market.setPrice(nov29, "EURCHF", x)
market.setPrice(nov29, "CHFEUR", 1/x)
portfolio.setMarket(market)
print x, ",", portfolio.getProfit(nov29) - portfolio.totalCost(), ",", debt.getProfit(nov29)






Maybe in future I will extend my library to create the portfolios and even to manage my SVM and other automatic trading. And, for sure, I will develop a "secret weapon" to join fundamental with technical analysis; who knows...

No comments:

Post a Comment