Skip to content

Instantly share code, notes, and snippets.

View ivank2139's full-sized avatar
🏠
Working from home

Ivan S Kirkpatrick ivank2139

🏠
Working from home
View GitHub Profile
func findShortestEdgeFromNode(node Node) Edge {
minimumEdge := MaxEdge
for _, edge := range Edges {
if edge.Node1.Name != node.Name || EdgeContains(UsedEdges, edge) {
continue
}
if edge.Length.LessThan(minimumEdge.Length) && !NodeContains(VisitedNodes, edge.Node2) {
log.Trace.Println("\nReplaced minimumEdge with shorter edge " + edge.String())
minimumEdge = edge
}
func ProcessEdges(node Node) {
if NodeContains(VisitedNodes, node) {
return
}
EdgeCount += 1
VisitedNodes = append(VisitedNodes, node)
edge := findShortestEdgeFromNode(node)
RouteEdges = append(RouteEdges, edge)
TotalDistance = TotalDistance.Add(edge.Length)
NextNode = Nodes[edge.Node2.Name]
@ivank2139
ivank2139 / CalculateEdges.go
Created October 26, 2020 19:57
Generate the edges from the nodes
func CalculateEdges(listEdges bool) string {
var sbldr = strings.Builder{}
for _, co := range Nodes {
for _, ci := range Nodes {
if co.Name == ci.Name {
log.Trace.Println("Skipping " + co.Name + " and " + ci.Name)
continue
}
diffXSq := co.XCoord.Sub(ci.XCoord).Abs().Pow(decimal.NewFromInt(2))
diffYSq := co.YCoord.Sub(ci.YCoord).Abs().Pow(decimal.NewFromInt(2))
@ivank2139
ivank2139 / GenNodes.go
Created October 26, 2020 19:52
Generates 26 named nodes using random x y coordinates
func GenNodes() string {
var sbldr = strings.Builder{}
for _, node := range NodeNames {
x := decimal.NewFromInt(int64(rand.Intn(GridMax-GridMin) + GridMin))
y := decimal.NewFromInt(int64(rand.Intn(GridMax-GridMin) + GridMin))
if !colocation(x, y) {
Nodes[node] = *NewNode(node, x, y)
} else {
log.Error.Println("Found colocated instance")
}
func FindOriginNode(listNodes bool) string {
originDist := float64(100 * 100)
for _, node := range Nodes {
sqd, _ := node.XCoord.Pow(decimal.NewFromInt(2)).Add(node.YCoord.Pow(decimal.NewFromInt(2))).Float64()
d := math.Sqrt(sqd)
if d < originDist {
originDist = d
OriginNode = node
}
}
func GenNodesFixed() string {
var sbldr = strings.Builder{}
xray := []float64{100, 56.84, 1.87, 30, 92.66, 81.67, 16, 9.04, 72.8, 97.2, 40.11, 0.1, 46.24, 98.88, 67.12, 5.81, 20.79, 86.21, 89.11, 24.49, 3.91, 62.91, 99.62, 50.66, 0.56, 35.82, 95.56}
yray := []float64{50, 99.53, 63.55, 4.17, 23.92, 88.69, 86.66, 21.33, 5.5, 66.5, 99.01, 46.9, 0.14, 39.46, 96.98, 73.39, 9.42, 15.52, 81.15, 93, 30.61, 1.69, 56.18, 100, 57.49, 2.05, 29.4}
i := 0
for _, node := range NodeNames {
x := decimal.NewFromFloat(xray[i])
y := decimal.NewFromFloat(yray[i])
Nodes[node] = *NewNode(node, x, y)
i++
@ivank2139
ivank2139 / KeikoAdvisory.txt
Created April 5, 2020 23:01
Keiko's buy, sell recommendations for selected crypto assets.
Processing 6 input files.
Processing Btc
Buy recommendation 0.04 Btc at price 6627.16, cost $270.13 on 2019-12-18
Sell Recommendation 0.07 Btc at price 9592.18, earn $669.88 on 2020-02-06
Cash available $1480.27, Btc available 0.21, portfolio total $2890.86
Buy recommendations 9, Sale recommendations 15
Processing Eth
Sell Recommendation 159.62 Eth at price 193.34, earn $30861.1 on 2019-10-10
@ivank2139
ivank2139 / summary.txt
Created April 5, 2020 06:47
A one line bash script tails the reports for the last 4 lines and outputs to the summary.txt file.
==> HistoryAnalysisBTC.txt <==
Sell Recommendation 0.07 Btc at price 9592.18, earn $669.88 on 2020-02-06
After trade, cash available $1480.27, Btc available 0.21, portfolio total $3489.92
Buy recommendations 9, Sale recommendations 15
==> HistoryAnalysisETH.txt <==
Buy recommendation 135.1 Eth at price 132.72, cost $17930.83 on 2019-12-17
After trade, cash available $53792.5, Eth available 613.96, portfolio total $135279.32
Buy recommendations 13, Sale recommendations 8
@ivank2139
ivank2139 / HistoryAnalysisETH.txt
Created April 5, 2020 04:34
The report created by the Keiko Analyzer.
Initial Cash $1000, Initial Eth 0, Initial Portfolio value $1000
Buy recommendation 286.03 Eth at price 0.87, cost $250 on 2015-09-14
After trade, cash available $750, Crypto available 286.03, portfolio total $1000
Buy recommendation 321.58 Eth at price 0.58, cost $187.5 on 2015-09-28
After trade, cash available $562.5, Crypto available 607.61, portfolio total $916.77
Buy recommendation 319.77 Eth at price 0.44, cost $140.62 on 2015-10-21
After trade, cash available $421.88, Crypto available 927.38, portfolio total $829.71
@ivank2139
ivank2139 / analyzer.go
Created April 5, 2020 04:21
The logic for determining if a buy or sell trade is recommended.
func Analyzer() {
readCsvFile()
macd := NewMacd()
rsi := NewRsi()
trend := NewTrend()
obv := NewObv()
priceClose, err := decimal.NewFromString("0")
volume, err := decimal.NewFromString("0")
check(err)
rsiB := false