Skip to content

adjust log format in LogTradesAnalysis Analyze#6

Open
beaquant wants to merge 11 commits intosdcoffey:mainfrom
beaquant:master
Open

adjust log format in LogTradesAnalysis Analyze#6
beaquant wants to merge 11 commits intosdcoffey:mainfrom
beaquant:master

Conversation

@beaquant
Copy link

@beaquant beaquant commented Dec 4, 2018

use local time make more readability
add orderside string for trades analysis. because EntranceOrder may not be bought, but sold.

eric and others added 2 commits December 4, 2018 09:58
2. adjust profit calculation in LogTradesAnalysis Analyze
Copy link
Owner

@sdcoffey sdcoffey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @beaquant,

I think this looks ok. I have a couple concerns though. The name of the PR suggests one thing, but you've actually added a new rule as well as updating the log format of LogTradesAnalysis. I'd like to see the stop gain rule in a separate PR. Of the changes you listed, I've suggested a number of comments above. In addition, the tests are failing. You'll need to update those before we can move forward.


profit := trade.ExitValue().Sub(trade.CostBasis())
fmt.Fprintln(lta.Writer, fmt.Sprintf("%s - enter with %s %s (%s @ $%s)",
trade.EntranceOrder().ExecutionTime.Format(time.RFC822), trade.EntranceOrder().Side, trade.EntranceOrder().Security, trade.EntranceOrder().Amount, trade.EntranceOrder().Price))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off here.

tolerance big.Decimal
}

type stopGainRule struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually don't need to define a duplicate struct here, since this one is private. I would redefine the above rule as

type stopRule struct {
    Indicator
    tolerace big.Decimal
}

and then make an alias for both stopLoss rule and stopGain rule, eg.

type stopLossRule = stopRule
type stopGainRule = stopRule

}

openPrice := record.CurrentPosition().CostBasis()
openPrice := record.CurrentPosition().EntranceOrder().Price
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a breaking change. EntranceOrder().Price reflects the unit price you paid for a security, not the total value of the position. Even though I think what you're doing here isn't incorrect, it would be breaking change for anyone who was depending on this behavior.

rule_stop.go Outdated
openPrice := record.CurrentPosition().CostBasis()
openPrice := record.CurrentPosition().EntranceOrder().Price
loss := slr.Indicator.Calculate(index).Div(openPrice).Sub(big.ONE)
if record.currentPosition.IsShort() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to avoid using the private fields when you can. Here you should replace record.currentPosition with record.CurrentPosition()

return loss.LTE(slr.tolerance)
}

// NewStopLossRule returns a new rule that is satisfied when the given loss tolerance (a percentage) is met or exceeded.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs are wrong here and on the line below

@beaquant
Copy link
Author

thanks, I'll double check it again

Base automatically changed from master to main February 27, 2021 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants