-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
93 lines (73 loc) · 3.45 KB
/
index.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
//Bootstrap
const fs = require('fs');
const moment = require('moment-timezone');
const data = require('./lib/data.js');
const stats = require('./lib/stats.js');
const view = require('./lib/view.js');
const singleView = require('./lib/singleView.js');
const doubleView = require('./lib/doubleView.js');
const email = require('./lib/email.js');
const chat = require('./lib/rocketchat.js');
const c2c = require('./models/c2c.js');
const yz = require('./models/yangZhang.js');
const atr = require('./models/atr.js');
const trueRange = require('./models/trueRange.js');
//Config
const instrument = process.argv[2];
const tickSize = process.argv[3];
const open = process.argv[4];
const close = process.argv[5]
const period = parseInt(process.argv[6]);
const recipients = process.argv[7];
const chatRoom = process.argv[8];
//Pull Data and Process
data(instrument, open, close, period, function(source){
//Build out the data models
const c2cData = [...source];
const close2CloseModel = c2c(period, c2cData, stats);
const c2cOutput = view.markdown(instrument, tickSize, c2cData[0].date, period, c2cData[0].close, 'Close-to-Close', close2CloseModel);
const c2cHtml = view.html(instrument, tickSize, c2cData[0].date, period, c2cData[0].close, 'Close-to-Close', close2CloseModel);
//TODO - FIX
const yzData = [...source];
const yangZhangModel = yz(period, yzData, stats);
// const yzOutput = view.markdown(instrument, tickSize, yzData[0].date, period, yzData[0].close, 'Yang Zhang', yangZhangModel);
// const yzHtml = view.html(instrument, tickSize, yzData[0].date, period, yzData[0].close, 'Yang Zhang', yangZhangModel);
const yzOutput = '';
const yzHtml = ``;
//ATR
const atrData = [...source];
const atrModel = atr(period, atrData, stats);
const trData = [...source];
const trModel = trueRange(period, trData, stats);
const trOutput = doubleView.markdown(instrument, tickSize, atrData[0].date, period, atrData[0].close, 'True Range', 'ATR', atrModel, 'True Range (2Sigma)', trModel.stdDev * 2);
const trHtml = doubleView.html(instrument, tickSize, atrData[0].date, period, atrData[0].close, 'True Range', 'ATR', atrModel, 'True Range (2Sigma)', trModel.stdDev * 2);
console.log(atr);
//Format Output
const markdown = `## ${instrument}
Calculated from a ${period} period rolling window of ${open} to ${close} sessions.
${c2cOutput}
${trOutput}
Subscribe to additional markets at [https://volatilityestimator.com/](https://volatilityestimator.com/).`;
const html = `<h2>${instrument}</h2>
<p>Calculated from a ${period} period rolling window of ${open} to ${close} sessions.</p>
${c2cHtml}
${trHtml}
<br /><br />
<p>Subscribe to additional markets at <a href="https://volatilityestimator.com/">VolatilityEstimator.com</a>.</p>`;
const text = `*${instrument} - Volatility Report for ${moment().format('YYYY-MM-DD')}* - ${period} period rolling window of ${open} to ${close} sessions
${view.aggregateText(instrument, tickSize, c2cData[0].date, period, open, close, c2cData[0].close, close2CloseModel, yangZhangModel)}
Subscribe to additional markets at: https://volatilityestimator.com
`;
// Write output to output file and to the console
fs.writeFileSync(`output/${instrument.replace(/\W/g,'')}.md`, markdown);
console.log(markdown);
//Email Report
if (recipients) {
email(recipients, `${instrument} Volatility Report for ${moment().format('YYYY-MM-DD')}`, html);
}
// Post to RocketChat
if (process.env.ROCKETCHAT_API_URL && chatRoom) {
chat.post(chatRoom, text);
}
});