#run tasks one by one = synchronous
import asyncio
import time
async def task(num):
print(f'start task {num}')
await asyncio.sleep(1)
i = 0
while(i < 10000000):
i += 1
print(f'done task {num}')
async def main():
print(f"started at {time.strftime('%X')}")
await task(1)
await task(2)
await task(3)
await task(4)
await task(5)
print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
----------------------------
#logs
#took 9 seconds to finish
started at 08:06:39
start task 1
done task 1
start task 2
done task 2
start task 3
done task 3
start task 4
done task 4
start task 5
done task 5
finished at 08:06:48
---------------------------
#run tasks concurrently = multiprocess
import asyncio
import time
#when current task is in idle, other tasks start to run
async def task(num):
print(f'start task {num}')
await asyncio.sleep(1)
i = 0
while(i < 10000000):
i += 1
print(f'done task {num}')
async def main():
print(f"started at {time.strftime('%X')}")
task1 = asyncio.create_task(task(1))
task2 = asyncio.create_task(task(2))
task3 = asyncio.create_task(task(3))
task4 = asyncio.create_task(task(4))
task5 = asyncio.create_task(task(5))
await task1
await task2
await task3
await task4
await task5
print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
-----------------------------
#logs
#finish in 5 seconds
started at 08:11:33
start task 1
start task 2
start task 3
start task 4
start task 5
done task 1
done task 3
done task 5
done task 2
done task 4
finished at 08:11:38
reference:
https://realpython.com/async-io-python/
https://docs.python.org/3/library/asyncio-task.html#coroutine
Tuesday, 14 January 2020
Monday, 13 January 2020
python multiprocessing
#pycharm
import time
import multiprocessing
start = time.perf_counter()
def do_something(seconds):
print(f'Sleep {seconds} second...')
time.sleep(seconds)
print('Done sleeping')
processes = []
if __name__ == '__main__':
for _ in range(10):
p = multiprocessing.Process(target=do_something, args=[1.5])
p.start()
processes.append(p)
for process in processes:
process.join()
finish = time.perf_counter()
print(f'finish in {round(finish-start, 3)} seconds')
------------------------------
#logs
PS C:\Users\bob\python_multiprocessing> python app.py
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
finish in 1.221 seconds
reference:
https://www.youtube.com/watch?v=fKl2JW_qrso
https://stackoverflow.com/questions/18204782/runtimeerror-on-windows-trying-python-multiprocessing
import time
import multiprocessing
start = time.perf_counter()
def do_something(seconds):
print(f'Sleep {seconds} second...')
time.sleep(seconds)
print('Done sleeping')
processes = []
if __name__ == '__main__':
for _ in range(10):
p = multiprocessing.Process(target=do_something, args=[1.5])
p.start()
processes.append(p)
for process in processes:
process.join()
finish = time.perf_counter()
print(f'finish in {round(finish-start, 3)} seconds')
------------------------------
#logs
PS C:\Users\bob\python_multiprocessing> python app.py
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Sleep 1 second...
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
Done sleeping
finish in 1.221 seconds
reference:
https://www.youtube.com/watch?v=fKl2JW_qrso
https://stackoverflow.com/questions/18204782/runtimeerror-on-windows-trying-python-multiprocessing
Sunday, 12 January 2020
太乙仙魔录之灵飞纪
歌词
亘古的火焰混沌中睁开了眼, 久远的星河越过时间。
沉静的水面是劫难或是机缘, 跌宕的命运挣开锁链。
这一把传世的剑, 这几世追寻的信念。
是要守护的诺言, 共赴这一场惊世的波澜。
给我参透这道心的眼, 让我超脱这红尘的牵绊。
天地无欲无为相离相连, 尘世有劫有缘或虚或玄。
杀伐破灭牺牲转眼成云烟, 是魔是仙不过一念之间。
天地无欲无为相离相连, 尘世有劫有缘或虚或玄。
仙道还是魔元难分难辨, 一生一息转眼又是万年。
剑起三尺青峰啸鸣, 踏歌行连天地之意。
霜华尽三界风雷磨砺, 凝练出五行之精。
风起终落于炼人心, 御剑行动洪荒之力。
混沌清寒芒开天辟地, 冻裂万年的洗礼。
剑飞扬紫霄碧落, 人穿梭黄泉生死薄, 道魔两清浊于人剑相合。
那一刹惊鸿破苍穹, 霹雳动山洪, 心念间扫却一切魔怮。
执念斩不休, 逍遥本难求, 挥舞间寻一个灵飞九州。
哈轻叹一声, 天上天下茫茫。
说飘莲一梦, 浮生铅华思量。
成败昆仑烽火天, 剑酒云间忘伊。
回望青山绿水上, 仗剑如我却不知真情何模样。
梦一生疯一场空彷徨,却难忘鬓如霜泪千行你的模样, 到最后赢遍天下会怎样。
落霞余只影, 对酒千里万里人在天涯。
Saturday, 11 January 2020
deploy react-yahoo-fin to surge.sh
project site: http://chuanshuoge-stockcharts.surge.sh/
code link: https://github.com/chuanshuoge6/stockcharts
//cmd
npm install --global surge
cd C:\Users\bob\Desktop\react-yahoo-fin\
npm run build
cd build\
surge
C:\Users\bob\Desktop\react-yahoo-fin\build>surge
Running as zchen2014chuanshuo@yahoo.com (Student)
project: C:\Users\bob\Desktop\react-yahoo-fin\build\
domain: chuanshuoge-stockcharts.surge.sh
upload: [====================] 100% eta: 0.0s (20 files, 7853769 bytes)
CDN: [====================] 100%
IP: 45.55.110.124
-----------------------------------------
//app.js
import React, { useState, useEffect } from 'react';
import './App.css';
import { Button, Tabs, Progress, Menu, Radio, Input, Affix } from 'antd';
import ReactHtmlParser from 'react-html-parser';
import HistoryGraph from './HistoricGraph';
import useInterval from '@use-it/interval';
const config = require('./config');
const axios = require('axios');
const { TabPane } = Tabs;
const { SubMenu } = Menu;
function App() {
const [tickers, settickers] = useState(null)
const [ticker_loaded, setticker_loaded] = useState(0)
const [ticker_radio, setticker_radio] = useState('AAPL')
const [about_api, setabout_api] = useState(null)
const [active_menu, setactive_menu] = useState('dow')
const [analyst_info, setanalyst_info] = useState(null)
const [balance_sheet, setbalance_sheet] = useState(null)
const [cash_flow, setcash_flow] = useState(null)
const [holder, setholder] = useState(null)
const [income, setincome] = useState(null)
const [quote, setquote] = useState(null)
const [stats, setstats] = useState(null)
const [historic_price, sethistoric_price] = useState(null)
const [live_price, setlive_price] = useState(0)
useEffect(() => {
document.title = "yahoo_fin"
//load all tickers
axios({
method: 'get',
url: config.URL + 'stocks/tickers/',
onDownloadProgress: progressEvent => {
setticker_loaded(parseInt(progressEvent.loaded / progressEvent.total * 100))
},
})
.then((response) => {
settickers(response.data)
console.log(response.data)
})
.catch((error) => {
console.log(error)
})
}, [])
useInterval(() => {
//get live price every second
axios({
method: 'post',
url: config.URL + 'stocks/live/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setlive_price(parseFloat(response.data['price']).toFixed(2))
})
.catch((error) => {
console.log(error)
})
}, 1000);
const about_yahoo_fin = () => {
//yahoo_fin api page
axios({
method: 'get',
url: config.URL + 'stocks/about_yahoo_fin/',
})
.then((response) => {
setabout_api(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_analysts_info = () => {
//get_analysts_info
axios({
method: 'post',
url: config.URL + 'stocks/analysts/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setanalyst_info(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_balance_sheet = () => {
//get_balance_sheet
axios({
method: 'post',
url: config.URL + 'stocks/balance/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setbalance_sheet(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_cash_flow = () => {
//get_cash_flow
axios({
method: 'post',
url: config.URL + 'stocks/cash/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setcash_flow(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_holders = () => {
//get_holders
axios({
method: 'post',
url: config.URL + 'stocks/holder/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setholder(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_income_statement = () => {
//get_income_statement
axios({
method: 'post',
url: config.URL + 'stocks/income/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setincome(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_quote_table = () => {
//get_quote_table
axios({
method: 'post',
url: config.URL + 'stocks/quote/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setquote(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_stats = () => {
//get_stats
axios({
method: 'post',
url: config.URL + 'stocks/stats/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
setstats(response.data)
})
.catch((error) => {
console.log(error)
})
}
const get_history = () => {
//get_data
axios({
method: 'post',
url: config.URL + 'stocks/history/',
data: {
'ticker': ticker_radio,
}
})
.then((response) => {
sethistoric_price(response.data)
console.log(response.data)
})
.catch((error) => {
console.log(error)
})
}
//left tab click event
const tabChange = (key) => {
switch (key) {
case '2':
get_analysts_info()
break
case '3':
about_yahoo_fin()
break
case '4':
get_balance_sheet()
break
case '5':
get_cash_flow()
break
case '6':
get_holders()
break
case '7':
get_income_statement()
break
case '8':
get_quote_table()
break
case '9':
get_stats()
break
case '10':
get_history()
break
default:
break
}
}
//Tickers tab menu click event
const menuClick = (e) => {
setactive_menu(e.key)
}
//Tickers radio select event
const radioSelect = (e) => {
setticker_radio(e.target.value)
}
//Input ticker
const tickerInput = (e) => {
setticker_radio(e.target.value)
}
const startServer = () => {
window.open('http://chuanshuoge-stockcharts.herokuapp.com/stocks/about_yahoo_fin/')
}
return (
<div style={{ padding: '10px' }}>
{/* server will shut down when inactive for a long time, reactivate server to fetch data */}
<Button block type="primary" size='small' style={{ marginBottom: '10px' }}
onClick={() => startServer()}>
Start Yahoo_fin Server
</Button>
<Tabs tabPosition='left' defaultActiveKey="1" onChange={(key) => tabChange(key)}>
<TabPane tab="Tickers" key="1">
<Affix offsetTop={0}>
<span style={{ float: 'right', backgroundColor: 'white' }}>
<Input size="small" placeholder="input ticker" style={{ width: '100px' }}
onChange={(e) => tickerInput(e)} /> {}
Selected ticker: {ticker_radio}</span>
</Affix>
Loading tickers {}
<Progress type="circle" percent={ticker_loaded} width={20} /><br />
<a href='http://eoddata.com/symbols.aspx' target="_blank">NYSE Tickers</a> {'| '}
<a href='http://eoddata.com/stocklist/TSX.htm' target="_blank">TSE Tickers</a>
<Menu onClick={(e) => menuClick(e)} selectedKeys={[active_menu]} mode='horizontal'>
<Menu.Item key='dow'>Dow</Menu.Item>
<Menu.Item key='nasdaq'>Nasdaq</Menu.Item>
<Menu.Item key='sp500'>SP500</Menu.Item>
<Menu.Item key='other'>Other</Menu.Item>
</Menu><br />
{tickers ?
<Radio.Group onChange={(e) => radioSelect(e)}>
{
tickers[active_menu].map((item, index) => {
return <Radio value={item} key={index}>{item}</Radio>
})
}
</Radio.Group>
: null}
</TabPane>
<TabPane tab="History" key="10">
Ticker: {ticker_radio} ${live_price}<br />
<HistoryGraph open={historic_price ? historic_price['open'] : null}
close={historic_price ? historic_price['close'] : null}
high={historic_price ? historic_price['high'] : null}
low={historic_price ? historic_price['low'] : null}
adjclose={historic_price ? historic_price['adjclose'] : null}
volume={historic_price ? historic_price['volume'] : null}
date={historic_price ? historic_price['date'] : null}>
</HistoryGraph>
</TabPane>
<TabPane tab="Analyst" key="2">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{analyst_info}</pre>
</TabPane>
<TabPane tab="Balance" key="4">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{balance_sheet}</pre>
</TabPane>
<TabPane tab="Cash" key="5">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{cash_flow}</pre>
</TabPane>
<TabPane tab="Holder" key="6">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{holder}</pre>
</TabPane>
<TabPane tab="Income" key="7">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{income}</pre>
</TabPane>
<TabPane tab="Quote" key="8">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{quote}</pre>
</TabPane>
<TabPane tab="Stats" key="9">
Ticker: {ticker_radio} ${live_price}<br />
<pre>{stats}</pre>
</TabPane>
<TabPane tab="Yahoo_fin" key="3">
{ReactHtmlParser(about_api)}
</TabPane>
</Tabs>
</div>
);
}
export default App;
https://surge.sh/
http://chuanshuoge2.blogspot.com/2020/01/react-stockcharts-macd.html
https://chuanshuoge2.blogspot.com/2019/10/react-hooks-useinterval.html
Friday, 10 January 2020
deploy django_yahoo_fin to heroku
create project on heroku
git init
heroku git:remote -a chuanshuoge-stockcharts
------------------------------
#power shell
heroku login
heroku buildpacks:set heroku/python
----------------------------
#create Procfile
web: gunicorn django_yahoo_fin.wsgi --log-file -
---------------------------
#create requirement.txt
pip freeze > requirements.txt
------------------------
#whitenoise static storage
#power shell
pip install Django whitenoise gunicorn
#django settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'build', 'static'),
]
-----------------------------
#generate static files
#powershell
python manage.py collectstatic
------------------------------
#allow heroku host
#django settings
ALLOWED_HOSTS = ['chuanshuoge-stockcharts.herokuapp.com']
---------------------------
#power shell
git add .
git commit -am "make it better"
git push heroku master
---------------------------
#heroku logs
PS C:\Users\bob\django_yahoo_fin> git push heroku master
Enumerating objects: 330, done.
Counting objects: 100% (330/330), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (325/325), done.
Writing objects: 100% (330/330), 924.13 KiB | 11.27 MiB/s, done.
Total 330 (delta 57), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip
remote: Collecting absl-py==0.8.0 (from -r /tmp/build_7742999d7d4343614a4dd97b94043bfd/requirements.txt (line 1))
remote: Downloading https://files.pythonhosted.org/packages/3c/0d/7cbf64cac3f93617a2b6b079c0182e4a83a3e7a8964d3b0cc3d9758ba002/absl-py-0.8.0.tar.gz (102kB)
remote: Collecting appdirs==1.4.3 (from -r /tmp/build_7742999d7d4343614a4dd97b94043bfd/requirements.txt (line 2))
remote: Downloading https://files.pythonhosted.org/packages/56/eb/810e700ed1349edde4cbdc1b2a21e28cdf115f9faf263f6bbf8447c1abf3/appdirs-1.4.3-py2.py3-none-any.whl
remote: Collecting asgiref==3.2.2 (from -r /tmp/build_7742999d7d4343614a4dd97b94043bfd/requirements.txt (line 3))
remote: Downloading https://files.pythonhosted.org/packages/d0/39/42344b1060cfb5542eecef3ce6dda3d2d5a89a660716ed5980635985f2a7/asgiref-3.2.2-py2.py3-none-any.whl
....
remote: Installing collected packages: six, absl-py, appdirs, asgiref, astor, soupsieve, beautifulsoup4, bs4, certifi, chardet, cliar, cssselect, cycler, sqlparse, pytz, django, django-cors-headers, django-jsonview, django-watchman, fake-useragent, wcwidth, prompt-toolkit, PyYAML, foliant, gast, google-pasta, grpcio, gunicorn, numpy, h5py, webencodings, html5lib, idna, javascript, MarkupSafe, Jinja2, joblib, Keras-Applications, Keras-Preprocessing, kiwisolver, lxml, Markdown, python-dateutil, pyparsing, matplotlib, mpl-finance, mpld3, nltk, pandas, urllib3, requests, pandas-datareader, parse, Pillow, protobuf, pyee, websockets, tqdm, pyppeteer, pyquery, w3lib, requests-html, scipy, scikit-learn, Werkzeug, tensorboard, wrapt, termcolor, tensorflow-estimator, tensorflow, tflearn, whitenoise, yahoo-fin
remote: Running setup.py install for absl-py: started
remote: Running setup.py install for absl-py: finished with status 'done'
remote: Running setup.py install for bs4: started
remote: Running setup.py install for bs4: finished with status 'done'
....
remote: Successfully installed Jinja2-2.10.3 Keras-Applications-1.0.8 Keras-Preprocessing-1.1.0 Markdown-3.1.1 MarkupSafe-1.1.1 Pillow-6.1.0 PyYAML-5.2 Werkzeug-0.16.0 absl-py-0.8.0 appdirs-1.4.3 asgiref-3.2.2 astor-0.8.0 beautifulsoup4-4.8.1 bs4-0.0.1 certifi-2019.9.11 chardet-3.0.4 cliar-1.3.4 cssselect-1.1.0 cycler-0.10.0 django-3.0a1 django-cors-headers-3.2.0 django-jsonview-1.2.0 django-watchman-0.18.0 fake-useragent-0.1.11 foliant-1.0.11 gast-0.3.2 google-pasta-0.1.7 grpcio-1.24.0 gunicorn-19.9.0 h5py-2.10.0 html5lib-1.0.1 idna-2.8 javascript-2015.32.59 joblib-0.14.0 kiwisolver-1.1.0 lxml-4.4.1 matplotlib-3.1.1 mpl-finance-0.10.0 mpld3-0.3 nltk-3.4.5 numpy-1.17.2 pandas-0.25.2 pandas-datareader-0.8.1 parse-1.14.0 prompt-toolkit-2.0.10 protobuf-3.9.2 pyee-6.0.0 pyparsing-2.4.2 pyppeteer-0.0.25 pyquery-1.4.1 python-dateutil-2.8.0 pytz-2019.2 requests-2.22.0 requests-html-0.10.0 scikit-learn-0.21.3 scipy-1.3.1 six-1.12.0 soupsieve-1.9.4 sqlparse-0.3.0 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 tflearn-0.3.2 tqdm-4.41.0 urllib3-1.25.6 w3lib-1.21.0 wcwidth-0.1.7 webencodings-0.5.1 websockets-8.1 whitenoise-4.1.4 wrapt-1.11.2 yahoo-fin-0.8.4
remote:
remote: -----> Downloading NLTK corpora…
remote: ! 'nltk.txt' not found, not downloading any corpora
remote: ! Learn more: https://devcenter.heroku.com/articles/python-nltk
remote: -----> $ python manage.py collectstatic --noinput
remote: Found another file with the destination path 'admin/css/widgets.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
remote: Found another file with the destination path 'admin/css/forms.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
....
remote: 0 static files copied to '/tmp/build_7742999d7d4343614a4dd97b94043bfd/static', 515 unmodified, 835 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 270.5M
remote: -----> Launching...
remote: Released v5
remote: https://chuanshuoge-stockcharts.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/chuanshuoge-stockcharts.git
* [new branch] master -> master
reference:
https://chuanshuoge2.blogspot.com/2019/08/django-67-deploy-to-heroku.html
https://devcenter.heroku.com/articles/getting-started-with-python#run-the-app-locally
git init
heroku git:remote -a chuanshuoge-stockcharts
------------------------------
#power shell
heroku login
heroku buildpacks:set heroku/python
----------------------------
#create Procfile
web: gunicorn django_yahoo_fin.wsgi --log-file -
---------------------------
#create requirement.txt
pip freeze > requirements.txt
------------------------
#whitenoise static storage
#power shell
pip install Django whitenoise gunicorn
#django settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'build', 'static'),
]
-----------------------------
#generate static files
#powershell
python manage.py collectstatic
------------------------------
#allow heroku host
#django settings
---------------------------
#power shell
git add .
git commit -am "make it better"
git push heroku master
---------------------------
#heroku logs
PS C:\Users\bob\django_yahoo_fin> git push heroku master
Enumerating objects: 330, done.
Counting objects: 100% (330/330), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (325/325), done.
Writing objects: 100% (330/330), 924.13 KiB | 11.27 MiB/s, done.
Total 330 (delta 57), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: Sqlite3 successfully installed.
remote: -----> Installing requirements with pip
remote: Collecting absl-py==0.8.0 (from -r /tmp/build_7742999d7d4343614a4dd97b94043bfd/requirements.txt (line 1))
remote: Downloading https://files.pythonhosted.org/packages/3c/0d/7cbf64cac3f93617a2b6b079c0182e4a83a3e7a8964d3b0cc3d9758ba002/absl-py-0.8.0.tar.gz (102kB)
remote: Collecting appdirs==1.4.3 (from -r /tmp/build_7742999d7d4343614a4dd97b94043bfd/requirements.txt (line 2))
remote: Downloading https://files.pythonhosted.org/packages/56/eb/810e700ed1349edde4cbdc1b2a21e28cdf115f9faf263f6bbf8447c1abf3/appdirs-1.4.3-py2.py3-none-any.whl
remote: Collecting asgiref==3.2.2 (from -r /tmp/build_7742999d7d4343614a4dd97b94043bfd/requirements.txt (line 3))
remote: Downloading https://files.pythonhosted.org/packages/d0/39/42344b1060cfb5542eecef3ce6dda3d2d5a89a660716ed5980635985f2a7/asgiref-3.2.2-py2.py3-none-any.whl
....
remote: Installing collected packages: six, absl-py, appdirs, asgiref, astor, soupsieve, beautifulsoup4, bs4, certifi, chardet, cliar, cssselect, cycler, sqlparse, pytz, django, django-cors-headers, django-jsonview, django-watchman, fake-useragent, wcwidth, prompt-toolkit, PyYAML, foliant, gast, google-pasta, grpcio, gunicorn, numpy, h5py, webencodings, html5lib, idna, javascript, MarkupSafe, Jinja2, joblib, Keras-Applications, Keras-Preprocessing, kiwisolver, lxml, Markdown, python-dateutil, pyparsing, matplotlib, mpl-finance, mpld3, nltk, pandas, urllib3, requests, pandas-datareader, parse, Pillow, protobuf, pyee, websockets, tqdm, pyppeteer, pyquery, w3lib, requests-html, scipy, scikit-learn, Werkzeug, tensorboard, wrapt, termcolor, tensorflow-estimator, tensorflow, tflearn, whitenoise, yahoo-fin
remote: Running setup.py install for absl-py: started
remote: Running setup.py install for absl-py: finished with status 'done'
remote: Running setup.py install for bs4: started
remote: Running setup.py install for bs4: finished with status 'done'
....
remote: Successfully installed Jinja2-2.10.3 Keras-Applications-1.0.8 Keras-Preprocessing-1.1.0 Markdown-3.1.1 MarkupSafe-1.1.1 Pillow-6.1.0 PyYAML-5.2 Werkzeug-0.16.0 absl-py-0.8.0 appdirs-1.4.3 asgiref-3.2.2 astor-0.8.0 beautifulsoup4-4.8.1 bs4-0.0.1 certifi-2019.9.11 chardet-3.0.4 cliar-1.3.4 cssselect-1.1.0 cycler-0.10.0 django-3.0a1 django-cors-headers-3.2.0 django-jsonview-1.2.0 django-watchman-0.18.0 fake-useragent-0.1.11 foliant-1.0.11 gast-0.3.2 google-pasta-0.1.7 grpcio-1.24.0 gunicorn-19.9.0 h5py-2.10.0 html5lib-1.0.1 idna-2.8 javascript-2015.32.59 joblib-0.14.0 kiwisolver-1.1.0 lxml-4.4.1 matplotlib-3.1.1 mpl-finance-0.10.0 mpld3-0.3 nltk-3.4.5 numpy-1.17.2 pandas-0.25.2 pandas-datareader-0.8.1 parse-1.14.0 prompt-toolkit-2.0.10 protobuf-3.9.2 pyee-6.0.0 pyparsing-2.4.2 pyppeteer-0.0.25 pyquery-1.4.1 python-dateutil-2.8.0 pytz-2019.2 requests-2.22.0 requests-html-0.10.0 scikit-learn-0.21.3 scipy-1.3.1 six-1.12.0 soupsieve-1.9.4 sqlparse-0.3.0 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 tflearn-0.3.2 tqdm-4.41.0 urllib3-1.25.6 w3lib-1.21.0 wcwidth-0.1.7 webencodings-0.5.1 websockets-8.1 whitenoise-4.1.4 wrapt-1.11.2 yahoo-fin-0.8.4
remote:
remote: -----> Downloading NLTK corpora…
remote: ! 'nltk.txt' not found, not downloading any corpora
remote: ! Learn more: https://devcenter.heroku.com/articles/python-nltk
remote: -----> $ python manage.py collectstatic --noinput
remote: Found another file with the destination path 'admin/css/widgets.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
remote: Found another file with the destination path 'admin/css/forms.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
....
remote: 0 static files copied to '/tmp/build_7742999d7d4343614a4dd97b94043bfd/static', 515 unmodified, 835 post-processed.
remote:
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 270.5M
remote: -----> Launching...
remote: Released v5
remote: https://chuanshuoge-stockcharts.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/chuanshuoge-stockcharts.git
* [new branch] master -> master
reference:
https://chuanshuoge2.blogspot.com/2019/08/django-67-deploy-to-heroku.html
https://devcenter.heroku.com/articles/getting-started-with-python#run-the-app-locally
Wednesday, 8 January 2020
react-stockcharts RSI and ATR
RSI formula
Once there are 14 periods of data available
Signals are considered overbought when the indicator is above 70% and oversold when the indicator is below 30%.
For example, imagine the market closed higher seven out of the past 14 days with an average gain of 1%. The remaining seven days all closed lower with an average loss of -0.8%. The calculation for the first part of the RSI would look like the following expanded calculation:
---------------------------------
ATR formula
ATR is not a directional indicator like MACD or RSI, but rather a unique volatility indicator that reflects the degree of interest or disinterest in a move. Strong moves, in either direction, are often accompanied by large ranges, or large True Ranges. This is especially true at the beginning of a move. Uninspiring moves can be accompanied by relatively narrow ranges. As such, ATR can be used to validate the enthusiasm behind a move or breakout.
-------------------------------
//HistoryGraph.js
import React, { useState, useEffect } from 'react';
import Kaji from './Kaji'
import HeikinAshi from './Heikin'
import CandleStickChartWithMACDIndicator from './MACD'
import CandleStickChartWithRSIIndicator from './RSI_ATR'
import { Menu } from 'antd';
function HistoryGraph(props) {
const { open, close, high, low, adjclose, volume, date } = props
const [data, setdata] = useState(null)
const [menu_select, setmenu_select] = useState('macd')
useEffect(() => {
if (adjclose) {
let ohlc = []
let i = 0
while (i < adjclose.length) {
//old date format %m/%d/%Y
const old_date = date[i].split('/')
ohlc.push(
{
'open': open[i],
'close': close[i],
'volume': volume[i],
'high': high[i],
'low': low[i],
//new date format y,m,d
'date': new Date(parseInt(old_date[2]), parseInt(old_date[0]) - 1, old_date[1])
}
)
i++
}
setdata(ohlc)
}
}, [props])
const menuClick = (e) => {
setmenu_select(e.key)
}
return (
<div>
<Menu onClick={(e) => menuClick(e)} selectedKeys={[menu_select]} mode="horizontal">
<Menu.Item key="kagi">
Kagi
</Menu.Item>
<Menu.Item key="heikin">
Heikin
</Menu.Item>
<Menu.Item key="macd">
MACD
</Menu.Item>
<Menu.Item key="rsi_atr">
RSI ATR
</Menu.Item>
</Menu>
{data && menu_select == 'kagi' ?
<Kaji data={data} width={1000} ratio={1} type='svg'></Kaji>
: null}
{data && menu_select == 'heikin' ?
<HeikinAshi data={data} width={1000} ratio={1} type='svg'></HeikinAshi>
: null}
{data && menu_select == 'macd' ?
<CandleStickChartWithMACDIndicator data={data} width={1000} ratio={1} type='svg'></CandleStickChartWithMACDIndicator>
: null}
{data && menu_select == 'rsi_atr' ?
<CandleStickChartWithRSIIndicator data={data} width={1000} ratio={1} type='svg'></CandleStickChartWithRSIIndicator>
: null}
</div>
);
}
export default HistoryGraph;
--------------------------------
//rsi_atr.js
https://github.com/rrag/react-stockcharts/blob/master/docs/lib/charts/CandleStickChartWithRSIIndicator.js
reference:
https://school.stockcharts.com/doku.php?id=technical_indicators:average_true_range_atr
https://www.investopedia.com/terms/r/rsi.asp
http://chuanshuoge2.blogspot.com/2020/01/react-stockchart-kagi.html
Subscribe to:
Posts (Atom)








