-
Notifications
You must be signed in to change notification settings - Fork 6
/
contractdetails.go
69 lines (51 loc) · 1.46 KB
/
contractdetails.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package thetagang
import (
"github.com/piquette/finance-go"
"math"
"github.com/piquette/finance-go/quote"
)
type ContractDetail struct {
Contract *finance.Contract
TotalCapital float64
}
func (c *ContractDetail) getPercentageReturn() float64 {
if c.Contract == nil {
return 0.0
}
costForOneContract := c.Contract.Strike * 100
totalNoContract := math.Floor(c.TotalCapital / costForOneContract)
totalPremium := totalNoContract * c.Contract.Bid * 100.00
totalPercentReturn := (totalPremium / c.TotalCapital) * 100.00
return totalPercentReturn
}
func (c *ContractDetail) getTotalPremiumEarned() float64 {
if c.Contract == nil {
return 0.0
}
costForOneContract := c.Contract.Strike * 100
totalNoContract := math.Floor(c.TotalCapital / costForOneContract)
totalPremium := totalNoContract * c.Contract.Bid * 100
return totalPremium
}
func (c *ContractDetail) getTotalNoOfContracts() float64 {
if c.Contract == nil {
return 0.0
}
costForOneContract := c.Contract.Strike * 100
totalNoContract := math.Floor(c.TotalCapital/ costForOneContract)
return totalNoContract
}
func (c *ContractDetail) getTwoHundredDayMA() float64 {
if c.Contract == nil {
return 0.0
}
q, _ := quote.Get(parseSymbol(c.Contract.Symbol))
return q.TwoHundredDayAverage
}
type ContractDetails []*ContractDetail
func (c ContractDetails) Len() int {
return len(c)
}
func (c ContractDetails) Less(i, j int) bool {
return c[i].getPercentageReturn() < c[j].getPercentageReturn()
}