MSBA7017 Financial Engineering

Pandas入门教程(二十二):股票数据分析实战——yfinance 获取数据、技术指标与收益率分析 把 Pandas 用在真实场景,才能体会它的价值。本文以茅台股票为例,用 yfinance 获取历史行情,完成缺失值处理与列筛选,绘制收盘价曲线,计算 SMA 移动平均线与 RSI 相对强弱指数,并通过日收益率、累计收益率和波动率完成完整的量化分析流程。 阅读详情

Assignment 1
Due: December 23, 2024 (Saturday), 11:59pm
MSBA7017 Financial Engineering, Fall 2023
Dr. Wang, Liao
lwang98@hku.hk
ˆ Any part with a single asterisk () is for extra credit; any part with a double asterisk
(**) will not be graded and only serves as food for thought.
ˆ For all questions involving coding, you are free to use existing codes for the numerical
examples in notes/slides; you can choose either VBA or Python.
ˆ For all questions involving coding, hand in the spreadsheet together with the VBA
codes or Python codes. You may print the spreadsheet and the VBA codes, or Python
codes, as hard copies and hand in it with solutions/answers for other problems. You
can also include the spreadsheet with VBA codes in a single .xlsm le (if you choose
VBA), or putting all Python codes in a zipped le (if you choose Python), and email
it to the Teaching Assistants (remember to include your name in the email).
ˆ Students are allowed to discuss and collaborate for the problems, but each student is
required to independently prepare the codes and the answers.
1 Coding: 20-Year Spot Rate Curve and Forward Rate
Curve (40%)
Download the le bondData.xlsx from Moodle. Below is a description of data:
ˆ The data contains U.S. treasury coupon bond prices with terms up to around 20 years.
ˆ 2/17/2023 in the A1 cell is the time stamp on which the all the prices are observed
In other words, it is the t in the bond price notation B(tT).
ˆ There are ve columns, Maturity , TTM, Coupon , price and yield . Each
row corresponds to one bond (observed on 2/17/2023).
1
ˆ Maturity contains the maturity dates; i.e., it is the T in B(t, T).
ˆ TTMstands for Time to Maturity , i.e. T t, the unit is one year.
ˆ Coupon stands for annual coupon rate. ( 0.01 means 1%.) U.S. treasury coupon
bonds pay coupons semiannually. This means, for a face value of $100 and coupon rate
0.01, every half year the coupon of amount $0.5 is paid. The last coupon together with
the face value is paid on maturity. For this assignment, use $100 as face value. The
function getBondCashFlows (codes available on Moodle in both VBA and Python)
for numerical examples we went through in class can help you to extract the cash
payment schedule for each bond in this dataset.
ˆ price is the observed bond price, and yield is the observed yield (calculated from the
price).
Complete the following tasks.
(a). Build a spot rate curve from this dataset. To deliver the solution, you need to: (i)
specify the spot rate model you use and why you choose this model; (ii) assessment of
goodness of t; you can do it in the same style as Slide 60 of Topic1a; (iii) plot the
price errors and the yield errors. Your choice of model/technique is not necessarily
limited to those discussed in this course. You may choose any other model/technique
you deem to be reasonable.
To complete this part, you need to compute the model-implied yields given the model
implied prices. The Excel spreadsheet built-in function YIELD can help you with
this. But to use this function, the bond price entered should be the clean price.
Speci cally, clean price = B(tT)- Accrued Interest, where B(tT) is the bond price
computed based on the spot rate curve model, and Accrued Interest (AI) is computed
as the following:
AI =face value coupon rate
frequency
t- previous coupon payment date
current coupon period length
For this assignment, face value = 100; frequency=2 (standing for semiannually
paid coupons); coupon rates are contained in the column of Coupon ; t is the
time stamp 2/17/2023 . previous coupon payment date is the coupon payment date
2
immediately before t, which can be retrieved by the spreadsheet function COUPPCD;
current coupon period length is the time between the coupon payment date imme
diately after t and the previous coupon payment date, and in particular the coupon
payment date immediately after t can be retrieved by the spreadsheet function COUP
NCD. For each bond, after AI is computed as described, for a model-implied bond
price B(tT), call the function YIELD to retrieve the model-implied yield. When
calling this function, settlement is 2/17/2023 , maturity is the maturity date in
the column Maturity , rate is the coupon rate contained in column Coupon , pr
is the clean price which equals B(tT)- AI described above, redemption is the face
value which equals $100; frequency equals 2; set basis at 1.
As an example for computing model-implied yield described above, look at the le
bonds allExamples.xlsm, the sheet Ex1 spotCurve p4 . The time stamp is 2/17/2023
set in cell A1. For each bond, column F computes the previous coupon payment date
by calling COUPPCD, column G computes the next coupon payment date by calling
COUPNCD, column H computes AI according to the formula above. In column J, the
function YIELD is called to compute the model-implied yield; in particular, for the
argument pr , the di erence between column I (containing model-implied bond price)
and the column H (containing AI) is entered.
Remark: if you choose Python, there is no readily available function to calculate yield,
so you need to implement on your own by solving the equation; the bisection method
is straightforward to implement.
(b). Write a function forwardRate to compute f(t t1 t1+ ) with given t, t1 and , based
on the spot rate curve built in (a). A reminder is that you need the function to have
access to s(t t1) and s(t t1 + ).
©. Use = 05 to build a forward rate curve and plot it with the spot rate curve on the
same graph. That is, for each t1 t on the x-axis, the y-axis value for spot rate curve
is s(t t1) and y-axis value for forward rate curve is f(t t1 t1 + ). Comment on the
graph.
(d). Using the spot rate curve you built in (a), develop an immunization strategy using
bonds in the given dataset for an obligation of amount $1 Million that will occur on
3
18 February 2026, based on Fisher-Weil Duration; you only need to give the number
of units to buy for each bond on the current time point (i.e. 2/17/2023 ).
(e).
When doing (a), what di culties did you encounter (e.g. long running time)? And
what limitations of your chosen curve tting techniques are suggested by these di
culties?
2 Computational Problems (45%)
You may need calculators to do numerical computations in some of the problems in this
section.
Problem 1
(a). We have a bond of face value $100 and an annual coupon rate of 2.5%. The coupon
payment is made every half year and the face value is paid with the last coupon on the
maturity date. That is, on each coupon payment date before the maturity date, the
bond pays $1.25, and on the maturity date, the payment is $101.25. The current time
is t, and the next coupon is known to happen on t + 025 (i.e. 3 months from now).
The maturity date of this bond is known to be T = t + 225. The annual yield now
is quoted at 188%. Use d = 05 (i.e. the length of the reference time interval length
is half a year). Compute the current bond price, B(tT); round the answer to two
decimal places.
You might need the formula for geometric sum: a + a2 +a3 + +an = a(1 an)
1 a
.
(b). Current time is t. Given the forward rate curve f(t t1 t2) (that is, t is xed, t1 and t2
span all pairs of (t1 t2) that satisfy t t1 t2), recover the spot rate curve s(t t).
©. Suppose there is a set of N zero-coupon bonds with maturities T1 < T2 <
< TN
(denote their prices now (t) by B0(tTn)). That is, the n-th bond makes only one
payment on its maturity date Tn (and pays nothing before Tn); suppose the payment
of n-th bond is Cn. Can you derive a discretely sampled spot rate curve (that is, obtain
the values of s(t t) for a set of speci c values of t) such that the bond prices implied
by this (discretely sampled) curve matches exactly with the observed prices? If yes,
4
derive this curve using the given zero-coupon bonds; in particular, specify which values
are used for t0 and the corresponding spot rates s(t t). If no, explain why.
(d). Your colleague ts a spot rate curve (from a certain class of bonds) that has the
following expression:
s(t t) = 006+0006(t t)+0001(t t)2 00005(t t)3 t t
(As usual, for spot rates we use the continuous compounding.) t is the current time.
Some client request a xed-income product that will pay $5000 on t+025 and $10000
on t +15, and you happen to be able to construct these two cash ows from a pool
of bonds that belong to the same class of bonds from which the spot rate curve is
tted. Compute the price that you will charge the client (before any fees). Suppose
you compute the price and quote it to the client, he/she thinks its fair and would like
to request another xed-income product. For this one, the client needs $10000 paid
on t +1 and $50000 on t+7. Do you have enough information to set a price for this
product? If yes, give the price; if no, explain why.
(e).** The discussion on bonds in this course is static, and changes in the underlying interest
rate structure are restricted to be local. Explain.
Problem 2
(a). Current time is t. Recall from (b) of the last problem: a zero-coupon bond makes a
one-shot payment which occurs on its maturity date. Show that both the Macaulay
duration and Fisher-Weil duration for a zero-coupon bond equal its time to maturity
(i.e. T
t). Based on this, argue that a long-term zero-coupon bond is riskier than a
short-term one.
(b). We have two bonds now (t). The rst bond is a zero-coupon bond: it matures on T
and makes only one payment which occurs on T. The second bond also matures on
T; and it makes two payments: one on t1 (t < t1 < T), and the other on T. Show
that both the Macaulay duration and Fisher-Weil duration of the rst bond are larger
than those for the second one. Based on this statement, argue that existence of cash
payments which occur before the maturity date tend to alleviate the bond risk.
5
©. We discussed an example of Forward Rate Agreement in class. Recall the setting: now
(t), two parties, call them A and B , agree to exchange cash ows on a future date
t2 > t. On t1 (t < t1 < t2), the spot rate prevailing from t1 to t2 will be observed,
denote it by s(t1 t2). On t2, A passes $es(t1 t2)(t2 t1) to B, and B passes ef(t2 t1) to A.
The rate f is agreed now (t). Weve shown that if A enters the FRA without cost
(i.e. the price charged on A to enter the FRA is 0), f should be set at the forward
rate f(t t1 t2). Now show the counter part: if it costs B $0 to enter the FRA, the f
should still be set at f(t t1 t2).
Now, suppose f > f(t t1 t2), compute the price for A to enter the FRA.
Problem 3
(a). (This is a drill to compute mean and variance) Two dice are independently rolled and
the two resulting values are multiplied together to form the quantity Z. For example,
if rst dice rolls 1 and the second dice rolls 6 then Z = 1 6 = 6. Compute E(Z) and
Var(Z).
(b). There are two stocks, A and B. Let rA and rB denote their returns for the following year.
We know: A := E(rA) = 10%, B := E(rB) = 15%; A := std(rA) = 15% and B :=
std(rB) = 25%. (std(X) stands for the standard deviation of the random variable X.)
The correlation coe cient between rA and rB is 08. (Recall, correlation coe cient
between two random variables X and Y is de ned as Cov(XY) (std(X)std(Y)).) Do
the following:
(i) Formulate the Markowitz mean-variance optimization model without risk-free asset
in this context; (ii) Find the global minimum variance portfolio (GMV); (iii) compute
the expected return of the GMV computed in (ii).
©.* Prove the Two Fund Theorem. (i.e. Theorem 1 in Notes 2).
6
3 Questions on FinTech (15%)
The questions in this section are open-ended, and we encourage any independent and creative
thinking.
Question 1

  1. P2P lending platform provides access to nancing by debts for small borrowers. On the
    investor s side, it provides new investment options by debts. And from the assigned readings,
    we know they are considered to be a promising new asset class . Compare and contrast
    the debts posted on P2P lending platforms with the bonds we discussed in this course.
  2. Give some examples of crowdfunding platforms in your home country; if there is no such
    platform in your home country, you can give examples from other countries that you are
    familiar with. If you want to initiate a project which you believe to be very pro table and
    will bring a 20% return on capital after two years, which platform from your examples will
    you consider to fund the project? If you want to shoot a movie about your postgraduate
    study experience and share it with people, which platform will you consider to raise the
    fund?
    Question 2
    The FinTech book considers Singapore as one of the FinTech hubs in Asia. Describe how
    FinTech is developing in your home country and the driving factors. Or, if it is not prospering
    in your home country, provide an explanation
如何处理动态语言(Python / JS)的“隐形”调用链? 本文揭示动态语言(Python/JS)中静态AST解析导致调用链“断链”的核心问题,提出通过运行时追踪补全图谱的解决方案。基于Code-Graph-RAG的cgr trace机制,分别利用pytest插件与V8 Profiler捕获真实调用路径,将动态边合并至静态图谱,并在权重体系中提升动态边优先级。实践表明,该方法可显著提升图谱覆盖率,实现“结构+行为”双视角理解代码,为MCP与Rerank系统提供可靠支持。 阅读详情

相关推荐

还在手敲LaTeX公式?用Rime小狼毫打造你的专属数学输入法(附完整配置包)

本文介绍如何利用Rime小狼毫输入法引擎打造专属数学公式输入方案,显著提升LaTeX公式输入效率。通过详细配置教程和智能补全技巧,帮助科研人员和学生实现3-5倍的输入速度提升,特别适合学术写作和技术文档创作场景。

weixin_32520601的博客 282

AI全栈实战 | 3.9-01 爬虫入门:requests 加 BeautifulSoup 三分钟跑通,但 90% 的人栽在这 4 个“礼貌“问题上

⚠️:本文内容仅用于。请遵守目标站点的服务条款与相关法律法规,不得对目标服务造成负担,不得采集、传播个人隐私数据。技术是中性的,边界在你手里。爬虫的入门技术(requests 发请求 + BeautifulSoup 解析)三分钟就能学会。真正区分"会用爬虫"和"会做爬虫的人"的,是这篇我们跑通"请求→解析→存储"的最小闭环,然后重点把"合规与礼貌"这根弦给你绷上。

源码获取 | 运行部署 | 定制二开修改,如果回复不及时请耐心等待,请见谅。 406

AMEsim不连续处理机制:仿真精度与效率的平衡艺术

本文深入解析AMEsim不连续处理机制在系统仿真中的应用,探讨如何平衡仿真精度与效率。通过液压系统仿真案例,详细介绍了事件检测算法、变步长求解器自适应策略及典型场景优化方法,帮助工程师有效应对仿真中的不连续性问题,提升仿真效率和准确性。

v4w5x6的博客 440

从一段视频到可漫游的 4D 有声场景:思路拆解与最小复现手记

只需一段手机视频,你就能生成可"走进去"的 4D 有声场景:转头时狗叫声方向随之变化,走近时声音更清晰。本文拆解 Video-to-4DAVScene 的核心思路,手把手带你用几十行 Python 搭出最小管线,把视频中的运动物体变成带空间位置的声源,并附上三个真实踩坑的排障经验,代码可直接跑。🎧

helloagent的博客 235

Excel数据透视表实战:分组折线图制作与动态分析指南

数据可视化是数据分析的关键环节,其核心原理在于将抽象数据转化为直观图形,以揭示趋势、对比差异。在众多图表类型中,折线图因其能清晰展示连续数据随时间或其他序列的变化趋势,而成为趋势分析的利器。其技术价值在于通过视觉编码,将多维数据关系降维呈现,从而辅助决策。在业务分析、运营监控等应用场景中,常需对比不同分组(如产品线、销售区域)在同一时间序列上的表现,这正是分组折线图要解决的核心问题。本文聚焦于利用Excel数据透视表这一强大工具,高效构建动态分组折线图,并深入探讨数据透视表在数据重塑和图表自动化中的实战应用

weixin_29057237的博客 381

Vue 实现华视身份证读卡器功能

在www.downcc.com下载“华视cvr100驱动”安装程序; 华视电子官网有相应的文档说明和程序下载 一、服务安装 选择安装目录: 启动读卡服务: 安装成功会有如图所示: 注意事项: 安装开发包必须使用管理员权限,因为windows服务和读卡器设备驱动程序均需要管理员权限,否则会安装失败。 win10需要修改组策略才有管理员权限。 二、服务的使用 打开浏览器,输入地址http://127.0.0.1:19196/mainpage,回车 点击openDevice: 点.

zyqgt960812的博客 6503

【每天一个 Python 小案例30】Python 基础知识综合小项目:我的工具盒

作为系列收官,本篇把前 29 篇的知识点合成一个能直接用的命令行工具"我的工具盒":计算器(用 ast 解析表达式,不碰 eval)、单位换算与温度转换(一张换算表 + 特例分支)、记账与分类统计(Decimal + JSON 持久化)、以及用"字典当命令表"把菜单和业务逻辑解耦的主循环。文中对比了 eval 的安全隐患与 ast 白名单的做法,解释了 lambda 闭包在字典里的写法与晚绑定陷阱,并在最后给出整个系列的知识地图,把变量、数据结构、控制流、函数、类、异常、文件、标准库八块内容对应到具体篇目。

xinjiyaya的博客 426

BOSS直聘数据采集、解析处理、分析与可视化实战

招聘和求职是一对永恒的话题,不论什么时候都有招聘或者是求职的需求,找不找得到工作可能最主要的就是匹配度是否高,待遇福利是否诱人,如今互联网的快速发展,找工作的方式早已发生了翻天覆地的变化,从以往的面对面形式的招聘简历投递和面试方式,变成了电子简历网络直接投递、远程面试录用的形式,便捷性大大提升,需求的快速增长,促生了一批互联网招聘类的企业,诸如:51job、BOSS直聘、拉勾网等等,为了能...

Together_CZ的博客 9025

详解Python条件语句

在 Python 中,if...else 是一种条件语句,可以根据给定的条件执行不同的操作。这个语句通常用于控制程序的流程。

2601_96798737的博客 207

rk3576 适配以太网(百兆)

百兆以太网,也常被称为快速以太网,是一种在1990年代中期推出的计算机网络技术标准。它相当于把当时主流的10兆以太网速度提升了10倍,最高能提供 100 Mbps 的传输速率,让文件共享、视频传输等网络应用变得流畅许多。它在数据链路层面完全保留了传统以太网的帧格式和MAC机制,这意味着现有的网络软件可以无缝对接,用户从10兆网络升级到百兆网络时,通常只需要更换网卡和集线器/交换机即可,非常方便。 在rk3576平台上,原生以太网接口支持百兆、千兆,还有pcie转换的2.5G。

weixin_35723192的博客 203

目前最强的价格行为技术分析AI!大A也能用!还免费!

有球友推荐了一个历史最强的价格行为技术分析AI工具,使用下来确实很惊艳,解决了 很多AI工具黑盒过程,难以回溯的问题,他的决策过程可解释,提供决策树、诊断结果、原始响应、调试信息和未来走势预期。用户能够看到模型为什么选择“做多、做空或不下单”。会检查置信度、入场条件、盈亏比、结构失效和冷却期。最大的优点不是“预测一定准确”,而是把主观的价格行为分析整理成了可重复、可解释、可校验、可持续跟踪的工程化流程。本文记录本项目在 Windows 上的实际部署与启动方法。

木头大左的博客 75

Python3 协程:异步编程的核心机制与实战

协程是解决I/O密集型任务等待瓶颈的高效机制,相比线程更轻量、无锁开销。从yield到async/await的演进,使异步编程语义清晰、易于理解。通过async/await可实现并发执行多个任务(如gather、create_task),显著提升网络请求、爬虫等场景性能。关键在于使用异步库(如aiohttp)替代同步库,避免阻塞事件循环。合理控制超时与并发数,才能发挥协程最大优势。

Lxn2zh的博客 159

rk3568 点亮双LVDS 屏

承接文章《rk3568点亮LCD(lvds)》中仅仅只能使用亮单LVDS;经过厂商的努力,陆续发布新补丁。目前支持双lvds显示,缺憾是需要自己额外移植相关补丁。受限于通信频率和VOP编码能力,支持最大分辨仍然是1920x1080、60fps。

weixin_35723192的博客 3007

torch.compile 差异仅 1e-6,边界样本预测为何翻转

torch.compile 加速后输出与 eager 不一致,部分预测翻转。逐层对比与 graph break 分析定位到动态分支翻转根因。容差回归仅适用于无分支翻转场景,零容忍场景应禁用编译。

昨日种种,皆成今我。今日种种,皆成新我。 159

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

二进制木马免杀-Python 分离免杀与 Web 挂马

二进制木马免杀-Python 分离免杀与 Web 挂马

2503_94637398的博客 268

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级 备考:莫队算法离线区间查询详解

备赛进行时:第十八届蓝桥杯软件赛报名已于 2026-10-08 10:00 开启、12-18 14:00 截止,省赛定在 2027-04-10(C/C++·Python 程序设计 9:00–13:00);中国电子学会 2026 年 12 月软件编程(C/C++ 一级至十级、Python 一级至六级)考级报名 9/23–12/2 16:00、统考 12-12;全国青少年信息素养大赛 2026—2027 赛季算法应用主题赛也已进入复盘练兵窗口。

IT_Scratch的博客 137

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

【Python】国家中小学智慧教育平台电子教材批量下载与 PDF 合成实战

成果:两本语文电子课本(一年级上册 118 页 / 23MB、三年级上册 130 页 / 30.3MB),合计 248 页、约 54MB,单本下载加合成 40~60 秒,PDF 页数校验全部通过。经验教训SPA 站点的数据接口优先从 bundle 里挖,比抓页面稳得多;资源链接要按 private/public 分组看待,只取平台公开部分;页数、目录名这类“可推断”的信息,永远用实际响应验证一次;受限环境里“能不能跑浏览器”要在方案定稿前确认。后续计划:这版 PDF 是图片版,没有文字层;

木头大左的博客 137

魔塔社区微调训练Qwen2-1.5B-Instruct模型并烧录到‌RK3568开发板教程

本文基于Ubuntu 22.04 + CUDA 13.0.3环境,使用LLaMA-Factory框架对Qwen2-1.5B-Instruct模型进行LoRA微调,训练儿童故事生成专用模型。通过配置qwen模板、制作alpaca格式数据集、执行sft训练并合并LoRA权重,最终将模型转换为GGUF格式,并量化为Q4_K_M以适配RK3568嵌入式平台。全程支持国产镜像加速下载与显存优化,实现高效轻量化部署。

浅清秋慕夏的博客 186

【回眸】DeepSeek V4.1 Flash 快速上手与实战

本文介绍如何高效本地部署开源大模型,通过现代化工具链实现分钟级环境搭建。聚焦显存优化、一键安装、代码调用与多轮对话实现,解决“显存不足”“连接超时”等痛点,提供参数调优与结构化输出技巧,助力开发者在离线场景下快速构建稳定、高效的本地推理系统。

啤酒鸭的物联网开发记录博客 223

智叟云集-手机证据抓取系统的工程结构与应用入口

本文系统阐述手机证据抓取系统的工程结构与应用入口,涵盖四大层面:工程目录划分(Android、Python服务、Web页面、测试与构建工具);Android组件通过Manifest声明可启动页面,主界面由MainActivity管理;Python服务通过run.py解析参数并启动FastAPI应用,支持远程访问;浏览器页面采用HTML/CSS/JS分离架构,静态资源通过路径关联,实现动态交互。各模块分工明确,协同构建可运行的采集系统。

2301_77178996的博客 232

Java Arrays.asList 常见坑详解|UnsupportedOperationException、数组联动、基本类型 bug

解析 Arrays.asList 常见开发陷阱,演示 UnsupportedOperationException、底层数组引用共享、基本类型数组问题,区分 Arrays 内部 ArrayList 与 java.util.ArrayList,给出数组转 List 的各种场景正确代码。

weixin_42617033的博客 473

利用python中matplotlib.pyplot库绘制图

plt.plot(x,y) # x,y是每个点的坐标,plot()把每个点按顺序画折线。plt.subplots(2,2)表示绘制2*2的子图布局,axs[0,0]表示在第0行第0列绘制子图...coordinates_i[:,0]表示获取每一行(每一个spot)的第0列(x坐标)coordinates_i[:,1]表示获取每一行(每一个spot)的第0列(y坐标)plot.subplot(2,2,1) 表示子图布局是2*2的,开始绘制第一个。也可以导入数据绘制。可以设置color属性,设置颜色。

qq_46147236的博客 102

Spring Boot 自动配置原理

Spring Boot 自动配置由 @EnableAutoConfiguration 导入选择器,读取 jar 中 .imports 候选清单,经去重、排序、排除后逐类做条件判断,通过才注册 Bean。延迟导入让用户 Bean 优先,@ConditionalOnMissingBean 使默认配置让位。失效时查清单和 Negative matches。

2401_89855466的博客 377

【随笔】KV缓存量化:省下的显存,要付出多少数值误差

用可运行量化器解释位宽、比例信息、分组和离群值的关系,核算KV缓存实际载荷,并给出Transformers配置与容量、延迟、质量验收方法。

code2cat的博客 455

【每天一个 Python 小案例29】Python 实现商品购物车

本篇实现一个购物车:商品目录、加入商品、修改数量、移除商品、查看小计、计算满减与 VIP 折扣、结算扣库存。核心设计是"目录与购物车分离"——目录存商品主数据,购物车只存 {商品编号: 数量};金额一律用 Decimal 并做 ROUND_HALF_UP 舍入。折扣部分讲清阶梯满减的匹配顺序(阈值从高到低、命中即停)与叠加顺序(先满减、后打折),并用一次完整结算演示 706 元如何变成 613.70 元。

xinjiyaya的博客 212

Python的字典

Python字典是存储键值对的数据结构,通过键(key)快速查找对应的值(value)。可使用{}定义,支持增删改查操作:通过dict[key]查询或修改值,get()方法安全获取并设置默认值,del dict[key]删除键值对,keys()、values()和items()用于遍历。items()结合双变量循环可高效遍历所有键值对,提升代码可读性与灵活性。

qq_43010954的博客 197
上一篇: MATH20621 - Coursework3
下一篇: COMP2402 lab4
todcode
博客等级 码龄7年 359粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值