abbass2 / pyqstrat

A fast, extensible, transparent python library for backtesting quantitative strategies.
BSD 3-Clause "New" or "Revised" License
353 stars 57 forks source link

How to Create Contract Groups Iteratively? #24

Closed BlackArbsCEO closed 2 years ago

BlackArbsCEO commented 2 years ago

For example if you want to backtest a portfolio of 20 stocks how do you create the contract groups without hardcoding each one as you did in your example for the pair trading strategy?

ko_prices['timestamp'] = pd.to_datetime(ko_prices.date)
pep_prices['timestamp'] = pd.to_datetime(pep_prices.date)

timestamps = ko_prices.timestamp.values

ko_contract_group = pq.ContractGroup.create('KO')
pep_contract_group = pq.ContractGroup.create('PEP')
BlackArbsCEO commented 2 years ago

I might have an idea

abbass2 commented 2 years ago

A contract group is for grouping PNL, for example,grouping options with different strikes and maturities. If you want to track PNL for each stock separately, then you would create a contract group for each. In this case, I would just do it in a loop.

cgs = {} for name in [ 'AAPL', 'IBM', 'MSFT']: cgs[name] = pq.ContractGroup.create(name)

On Thu, Jan 13, 2022 at 1:14 PM Brian @.***> wrote:

I might have an idea

— Reply to this email directly, view it on GitHub https://github.com/abbass2/pyqstrat/issues/24#issuecomment-1012431183, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCN2V47X4P4UKBV5PB3AMLUV4QA3ANCNFSM5L2LSGKQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>