siat 3.10.131__py3-none-any.whl → 3.10.133__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- siat/common.py +136 -3
- siat/grafix.py +1 -1
- siat/market_china.py +1 -1
- siat/markowitz2.py +240 -39
- siat/markowitz2_20250704.py +2969 -0
- siat/markowitz2_20250705.py +3158 -0
- siat/security_prices.py +42 -2
- siat/security_trend2.py +1 -1
- siat/stock.py +4 -2
- siat/translate.py +11 -11
- {siat-3.10.131.dist-info → siat-3.10.133.dist-info}/METADATA +10 -5
- {siat-3.10.131.dist-info → siat-3.10.133.dist-info}/RECORD +15 -13
- siat-3.10.133.dist-info/top_level.txt +3 -0
- siat-3.10.131.dist-info/top_level.txt +0 -1
- {siat-3.10.131.dist-info → siat-3.10.133.dist-info}/LICENSE +0 -0
- {siat-3.10.131.dist-info → siat-3.10.133.dist-info}/WHEEL +0 -0
siat/common.py
CHANGED
@@ -4962,10 +4962,9 @@ async def jupyter2pdf2(notebook_dir, notebook_file):
|
|
4962
4962
|
notebook_path=notebook_dir+sep+notebook_file1+'.ipynb'
|
4963
4963
|
|
4964
4964
|
# pdf文件的完整路径
|
4965
|
-
output_pdf_path1=notebook_dir+sep+notebook_file1+'A4.pdf'
|
4966
|
-
output_pdf_path2=notebook_dir+sep+notebook_file1+'A3.pdf'
|
4965
|
+
output_pdf_path1=notebook_dir+sep+notebook_file1+' A4.pdf'
|
4966
|
+
output_pdf_path2=notebook_dir+sep+notebook_file1+' A3.pdf'
|
4967
4967
|
|
4968
|
-
import os,sys
|
4969
4968
|
from nbconvert import HTMLExporter
|
4970
4969
|
|
4971
4970
|
"""
|
@@ -5053,6 +5052,140 @@ if __name__ == '__main__':
|
|
5053
5052
|
notebook_file = "Session 1 全球证券市场-简化版.ipynb"
|
5054
5053
|
#await jupyter2pdf2(notebook_dir, notebook_file)
|
5055
5054
|
# 注意:上面的await命令会导致编译失败,测试后要注释掉
|
5055
|
+
|
5056
|
+
#==============================================================================
|
5057
|
+
|
5058
|
+
|
5059
|
+
async def jupyter2pdf3(notebook_path):
|
5060
|
+
"""
|
5061
|
+
===========================================================================
|
5062
|
+
将 Jupyter Notebook 转换为 PDF 文件,异步方式。
|
5063
|
+
主要参数:
|
5064
|
+
notebook_path: Jupyter Notebook文件的完整路径,包括所在的目录和文件名
|
5065
|
+
获取方法:在Jupyter Notebook中执行下列命令(仅在交互环境中工作)
|
5066
|
+
notebook_path=globals().get("__session__")
|
5067
|
+
输出:
|
5068
|
+
同时生成A4和A3两种幅面的pdf文件,由使用者自行挑选一个效果最好的。
|
5069
|
+
返回:
|
5070
|
+
None
|
5071
|
+
|
5072
|
+
注意1:如果指令异常,可能还要执行python -m playwright install
|
5073
|
+
注意2:调用本函数的格式是异步await开头,例如:
|
5074
|
+
await jupyter2pdf3(notebook_path)
|
5075
|
+
"""
|
5076
|
+
DEBUG=False
|
5077
|
+
|
5078
|
+
import os,sys
|
5079
|
+
# 分离目录和文件名
|
5080
|
+
notebook_dir, notebook_file = os.path.split(notebook_path)
|
5081
|
+
|
5082
|
+
if DEBUG:
|
5083
|
+
print("目录路径:", notebook_dir) # 输出:/Users/peterwang/Documents/project
|
5084
|
+
print("文件名:", notebook_file) # 输出:data.csv
|
5085
|
+
|
5086
|
+
# 如果还想拆出文件名和扩展名
|
5087
|
+
name_only, ext = os.path.splitext(notebook_file)
|
5088
|
+
print("文件名(不含扩展名):", name_only) # 输出:data
|
5089
|
+
print("扩展名:", ext) # 输出:.csv
|
5090
|
+
|
5091
|
+
# 路径分割符号
|
5092
|
+
if ('/' in notebook_dir) and not ('\\' in notebook_dir):
|
5093
|
+
sep='/'
|
5094
|
+
else:
|
5095
|
+
sep='\\'
|
5096
|
+
|
5097
|
+
#import os; sep=os.sep
|
5098
|
+
|
5099
|
+
# ipynb文件的完整路径
|
5100
|
+
if ('.ipynb' in notebook_file):
|
5101
|
+
notebook_file1=notebook_file.replace('.ipynb','')
|
5102
|
+
else:
|
5103
|
+
notebook_file1=notebook_file
|
5104
|
+
notebook_path=notebook_dir+sep+notebook_file1+'.ipynb'
|
5105
|
+
|
5106
|
+
# pdf文件的完整路径
|
5107
|
+
output_pdf_path1=notebook_dir+sep+notebook_file1+' A4.pdf'
|
5108
|
+
output_pdf_path2=notebook_dir+sep+notebook_file1+' A3.pdf'
|
5109
|
+
|
5110
|
+
from nbconvert import HTMLExporter
|
5111
|
+
|
5112
|
+
"""
|
5113
|
+
import nest_asyncio
|
5114
|
+
nest_asyncio.apply() # 修复 Notebook 的事件循环问题
|
5115
|
+
"""
|
5116
|
+
|
5117
|
+
try:
|
5118
|
+
from playwright.async_api import async_playwright
|
5119
|
+
#from playwright.sync_api import sync_playwright
|
5120
|
+
except:
|
5121
|
+
print(" #Warning(jupyter2pdf2): playwright seems not fully installed yet")
|
5122
|
+
print(" [Solution] execute the command before re-run: playwright install")
|
5123
|
+
return
|
5124
|
+
|
5125
|
+
html_file = ""
|
5126
|
+
|
5127
|
+
try:
|
5128
|
+
# 导出 Notebook 为 HTML
|
5129
|
+
html_exporter = HTMLExporter()
|
5130
|
+
try:
|
5131
|
+
html_content, _ = html_exporter.from_filename(notebook_path)
|
5132
|
+
print(f"Converting {notebook_file} to pdf ...")
|
5133
|
+
|
5134
|
+
except:
|
5135
|
+
print("File not found for {}".format(notebook_path))
|
5136
|
+
return
|
5137
|
+
|
5138
|
+
# 创建临时 HTML 文件
|
5139
|
+
html_file = "temp_notebook.html"
|
5140
|
+
with open(html_file, "w", encoding="utf-8") as f:
|
5141
|
+
f.write(html_content)
|
5142
|
+
|
5143
|
+
# 使用 Playwright 打开 HTML 并保存为 PDF
|
5144
|
+
async with async_playwright() as p:
|
5145
|
+
browser = await p.chromium.launch()
|
5146
|
+
page = await browser.new_page()
|
5147
|
+
await page.goto(f"file://{os.path.abspath(html_file)}")
|
5148
|
+
|
5149
|
+
# 避免加载html文件超时,用于macOS
|
5150
|
+
if not sys.platform.startswith('win'):
|
5151
|
+
page.wait_for_selector(".jp-Notebook", state="visible", timeout=60000) # 等待笔记本主体出现
|
5152
|
+
|
5153
|
+
await page.pdf(path=output_pdf_path1, format='A4')
|
5154
|
+
await page.pdf(path=output_pdf_path2, format='A3')
|
5155
|
+
|
5156
|
+
await browser.close()
|
5157
|
+
"""
|
5158
|
+
with sync_playwright() as p:
|
5159
|
+
browser = p.chromium.launch()
|
5160
|
+
page = browser.new_page()
|
5161
|
+
page.goto(f"file://{os.path.abspath(html_file)}")
|
5162
|
+
|
5163
|
+
# 避免加载html文件超时,用于macOS
|
5164
|
+
if not sys.platform.startswith('win'):
|
5165
|
+
page.wait_for_selector(".jp-Notebook", state="visible", timeout=60000) # 等待笔记本主体出现
|
5166
|
+
|
5167
|
+
page.pdf(path=output_pdf_path1, format='A4')
|
5168
|
+
page.pdf(path=output_pdf_path2, format='A3')
|
5169
|
+
|
5170
|
+
browser.close()
|
5171
|
+
"""
|
5172
|
+
|
5173
|
+
print(f"2 PDFs created in {notebook_dir}")
|
5174
|
+
|
5175
|
+
except Exception as e:
|
5176
|
+
if str(e)=='':
|
5177
|
+
e="because of issues in your playwright or Python environment"
|
5178
|
+
print(f"PDF conversion failed {e}")
|
5179
|
+
return
|
5180
|
+
|
5181
|
+
finally:
|
5182
|
+
if html_file == "":
|
5183
|
+
return
|
5184
|
+
# 删除临时 HTML 文件
|
5185
|
+
elif os.path.exists(html_file):
|
5186
|
+
os.remove(html_file)
|
5187
|
+
|
5188
|
+
return
|
5056
5189
|
|
5057
5190
|
#==============================================================================
|
5058
5191
|
if __name__ == '__main__':
|
siat/grafix.py
CHANGED
@@ -365,7 +365,7 @@ def plot_line(df0,colname,collabel,ylabeltxt,titletxt,footnote,datatag=False, \
|
|
365
365
|
#av=str(round(av,2)) if av < 100 else str(int(av))
|
366
366
|
#av=str(int(av)) if abs(av) >= 100 else str(round(av,2)) if abs(av) >= 10 else str(round(av,3))
|
367
367
|
avstr=str(int(av)) if abs(av) >= 100 else str(round(av,2)) if abs(av) >= 10 else str(round(av,3))
|
368
|
-
plt.axhline(y=av,ls="dashed",c="blueviolet",linewidth=2,label=text_lang("本期间均值","Periodic mean")+avstr)
|
368
|
+
plt.axhline(y=av,ls="dashed",c="blueviolet",linewidth=2,label=text_lang("本期间均值","Periodic mean ")+avstr)
|
369
369
|
#footnote=footnote + ",均值"+av
|
370
370
|
#footnote=text_lang("注:期间均值","Note: Periodic mean ")+av+"; "+footnote
|
371
371
|
|
siat/market_china.py
CHANGED
@@ -1009,7 +1009,7 @@ def market_detail_china2(category='price',
|
|
1009
1009
|
ft4=heading+text_lang("☆涨速:平均每分钟股价变化率,表示股价变化速度\n","*Changing speed(涨速): rate of changes per minute\n")
|
1010
1010
|
ft5=heading+text_lang("☆5分钟涨跌:最新5分钟内股价的涨跌幅度\n","*5 min up-down(5分钟涨跌): changes recent 5 minutes\n")
|
1011
1011
|
ft6=heading+text_lang("☆振幅:最高最低价差绝对值/昨收,表示股价变化活跃程度\n","*Amplitude(振幅): (High - Low)/Prev Close\n")
|
1012
|
-
ft7=heading+text_lang("☆涨跌幅:(最新价-昨收)/昨收,表示相对昨日的变化程度\n","*Change%(涨跌幅): (Current Price/Prev Close - 1\n")
|
1012
|
+
ft7=heading+text_lang("☆涨跌幅:(最新价-昨收)/昨收,表示相对昨日的变化程度\n","*Change%(涨跌幅): (Current Price/Prev Close) - 1\n")
|
1013
1013
|
ft8=heading+text_lang("☆涨跌额:最新价-昨收,表示相对昨日的变化金额\n","*Change(涨跌额): Current Price - Prev Close\n")
|
1014
1014
|
|
1015
1015
|
ft9=heading+text_lang("☆使用实时数据,不同日期/每天不同时刻统计的结果可能不同\n","*Based on real-time data, vary with time\n")
|