Skip to content

Long-only strategy #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
riodda opened this issue May 22, 2020 · 4 comments
Closed

Long-only strategy #72

riodda opened this issue May 22, 2020 · 4 comments
Labels
question Not a bug, but a FAQ entry

Comments

@riodda
Copy link

riodda commented May 22, 2020

Hi, i would like to know if it's possible to create a long only strategy without short sell on position close.

@kernc
Copy link
Owner

kernc commented May 22, 2020

Sure, you just call Strategy.position.close().

@kernc kernc added the question Not a bug, but a FAQ entry label May 22, 2020
@kernc kernc changed the title Long Only Strategy Long-only strategy May 22, 2020
@kernc kernc closed this as completed May 22, 2020
@riodda
Copy link
Author

riodda commented May 22, 2020

Yes, this was my first taught, but i have

AttributeError: 'property' object has no attribute 'close' error.
I probably haven't got yet the librari structure.

I have a buy label from 0-1 and when the label goes over 0.5 i whant the stretegy to buy, if falls below to sell but not short.

`class RF_Label(Strategy):

def init(self):
    self.rf_buy = self.I(RF_buy, self.data.RF_Label, self.data.PP)
    super().init()
    
def next(self):
    if not self.position:  # not in the market
        if crossover(self.data.RF_Label,self.data.thersold):
            self.buy()
    else:
        if crossover(self.data.thersold,self.data.RF_Label):
            Strategy.position.close()`

@riodda
Copy link
Author

riodda commented May 22, 2020

Was actually quite easy, self.position.close().....

@kernc
Copy link
Owner

kernc commented May 22, 2020

Yeah, "Strategy" in Strategy.position.close() just stands for the reference class. The method/accessors are to be called on an instance of said class, here self. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but a FAQ entry
Projects
None yet
Development

No branches or pull requests

2 participants