个人所得税模拟器,MQL5计算汇率

简介: 多语言混合的个人所得税计算器项目(renjisuanhuimoxing),支持实时汇率获取、多币种收入换算与个税计算

下载地址:http://lanzou.com.cn/i1b90d57d

image.png

📁 output/renjisuanhuimoxing/
├── 📄 README.md199 B
├── 📄 pom.xml1.6 KB
├── 📄 package.json690 B
├── 📄 config/application.properties609 B
├── 📄 endpoints/Server.js3.8 KB
├── 📄 permissions/Dispatcher.php3.9 KB
├── 📄 src/main/java/Repository.java6.9 KB
├── 📄 config/Observer.json690 B
├── 📄 endpoints/Builder.ts3.6 KB
├── 📄 permissions/Pool.py5 KB
├── 📄 composables/Engine.sql3.8 KB
├── 📄 endpoints/Wrapper.js4 KB
├── 📄 utils/Queue.go3.9 KB
├── 📄 endpoints/Worker.go3.1 KB
├── 📄 endpoints/Parser.cpp1.5 KB
├── 📄 authentication/Registry.php3.3 KB
├── 📄 authentication/Util.cpp1.6 KB
├── 📄 authentication/Buffer.java7.3 KB
├── 📄 authentication/Converter.py4.4 KB
├── 📄 permissions/Cache.ts2.7 KB
├── 📄 lib/Handler.jar647 B
├── 📄 config/Proxy.xml1.5 KB
├── 📄 permissions/Executor.java6.4 KB
├── 📄 aggregate/Listener.js2.6 KB
├── 📄 aggregate/Transformer.py5 KB

项目编译入口:

Project Structure

Folder : renjisuanhuimoxing

Files : 26

Size : 78.7 KB

Generated: 2026-03-22 16:44:08

renjisuanhuimoxing/
├── README.md [199 B]
├── aggregate/
│ ├── Listener.js [2.6 KB]
│ └── Transformer.py [5 KB]
├── authentication/
│ ├── Buffer.java [7.3 KB]
│ ├── Converter.py [4.4 KB]
│ ├── Registry.php [3.3 KB]
│ └── Util.cpp [1.6 KB]
├── composables/
│ └── Engine.sql [3.8 KB]
├── config/
│ ├── Observer.json [690 B]
│ ├── Proxy.xml [1.5 KB]
│ └── application.properties [609 B]
├── endpoints/
│ ├── Builder.ts [3.6 KB]
│ ├── Parser.cpp [1.5 KB]
│ ├── Server.js [3.8 KB]
│ ├── Worker.go [3.1 KB]
│ └── Wrapper.js [4 KB]
├── lib/
│ └── Handler.jar [647 B]
├── package.json [690 B]
├── permissions/
│ ├── Cache.ts [2.7 KB]
│ ├── Dispatcher.php [3.9 KB]
│ ├── Executor.java [6.4 KB]
│ └── Pool.py [5 KB]
├── pom.xml [1.6 KB]
├── prompts/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── Repository.java [6.9 KB]
│ │ └── resources/
│ └── test/
│ └── java/
└── utils/
└── Queue.go [3.9 KB]

自动获取实时汇率

根据税率计算个人所得税

支持多币种收入换算

完整代码实现
cpp
//+------------------------------------------------------------------+
//| TaxCalculator.mq5 |
//| Copyright 2024, YourName |
//| https://www.yourwebsite.com|
//+------------------------------------------------------------------+

property copyright "Copyright 2024, YourName"

property link "https://www.yourwebsite.com"

property version "1.00"

property strict

// 输入参数
input double IncomeAmount = 5000.0; // 收入金额
input string IncomeCurrency = "USD"; // 收入币种
input string TaxCurrency = "CNY"; // 计税币种
input double TaxRate = 10.0; // 税率(%)
input double Deduction = 5000.0; // 起征点/免征额

// 全局变量
string apiKey = "YOUR_API_KEY"; // 汇率API密钥(需替换)
string url = "https://api.exchangerate-api.com/v4/latest/";

//+------------------------------------------------------------------+
//| 获取实时汇率 |
//+------------------------------------------------------------------+
double GetExchangeRate(string fromCurrency, string toCurrency)
{
string requestUrl = url + fromCurrency;
string headers = "Content-Type: application/json";
char postData[];
string response;

// 发送HTTP请求
int res = WebRequest("GET", requestUrl, headers, 5000, postData, response);

if(res == 200)
{
    // 解析JSON响应
    double rate = ParseJSONRate(response, toCurrency);
    if(rate > 0)
    {
        Print("成功获取汇率: 1 ", fromCurrency, " = ", rate, " ", toCurrency);
        return rate;
    }
}

Print("汇率获取失败,错误代码: ", res);
return -1;

}

//+------------------------------------------------------------------+
//| 解析JSON响应中的汇率 |
//+------------------------------------------------------------------+
double ParseJSONRate(string jsonResponse, string targetCurrency)
{
// 查找目标币种汇率字段
string searchStr = "\"" + targetCurrency + "\":";
int pos = StringFind(jsonResponse, searchStr);

if(pos >= 0)
{
    int startPos = pos + StringLen(searchStr);
    int endPos = StringFind(jsonResponse, ",", startPos);
    if(endPos < 0) endPos = StringFind(jsonResponse, "}", startPos);

    string rateStr = StringSubstr(jsonResponse, startPos, endPos - startPos);
    return StringToDouble(rateStr);
}

return -1;

}

//+------------------------------------------------------------------+
//| 计算个人所得税 |
//+------------------------------------------------------------------+
double CalculateTax(double income, double taxRate, double deduction)
{
double taxableIncome = income - deduction;

if(taxableIncome <= 0)
    return 0;

double tax = taxableIncome * (taxRate / 100.0);
return NormalizeDouble(tax, 2);

}

//+------------------------------------------------------------------|
//| 主函数 |
//+------------------------------------------------------------------+
void OnStart()
{
Print("===== 个人所得税计算器 =====");
Print("收入金额: ", IncomeAmount, " ", IncomeCurrency);
Print("计税币种: ", TaxCurrency);
Print("税率: ", TaxRate, "%");
Print("免征额: ", Deduction, " ", TaxCurrency);

// 获取汇率
double exchangeRate = 1.0;
if(IncomeCurrency != TaxCurrency)
{
    exchangeRate = GetExchangeRate(IncomeCurrency, TaxCurrency);
    if(exchangeRate <= 0)
    {
        Print("无法获取汇率,使用默认汇率1:1");
        exchangeRate = 1.0;
    }
}

// 币种换算
double incomeInTaxCurrency = IncomeAmount * exchangeRate;
Print("折算后收入: ", DoubleToString(incomeInTaxCurrency, 2), " ", TaxCurrency);

// 计算个税
double tax = CalculateTax(incomeInTaxCurrency, TaxRate, Deduction);
double netIncome = incomeInTaxCurrency - tax;

// 输出结果
Print("----------------------------");
Print("应纳税所得额: ", DoubleToString(incomeInTaxCurrency - Deduction, 2), " ", TaxCurrency);
Print("应缴个人所得税: ", DoubleToString(tax, 2), " ", TaxCurrency);
Print("税后收入: ", DoubleToString(netIncome, 2), " ", TaxCurrency);
Print("===== 计算完成 =====");

}

//+------------------------------------------------------------------+
//| 错误处理 |
//+------------------------------------------------------------------+
int OnInit()
{
// 检查网络连接
if(!TerminalInfoInteger(TERMINAL_CONNECTED))
{
Print("错误: 未连接到网络");
return INIT_FAILED;
}

// 启用WebRequest
if(!IsWebRequestAllowed())
{
    Print("错误: 请在终端设置中启用WebRequest功能");
    Print("路径: 工具 -> 选项 -> 智能交易系统 -> 允许WebRequest");
    return INIT_FAILED;
}

return INIT_SUCCEEDED;

}

//+------------------------------------------------------------------+
//| 检查WebRequest权限 |
//+------------------------------------------------------------------+
bool IsWebRequestAllowed()
{
string allowedUrls[];
int count = TerminalInfoInteger(TERMINAL_ALLOWED_WEBREQUESTS);

if(count > 0)
{
    for(int i = 0; i < count; i++)
    {
        string url;
        if(TerminalInfoString(TERMINAL_ALLOWED_WEBREQUESTS_URL, i, url))
        {
            if(StringFind(url, "api.exchangerate-api.com") >= 0)
                return true;
        }
    }
}

return false;

}
使用说明

  1. 环境配置
    在MT5终端中启用WebRequest功能

添加API域名到允许列表:https://api.exchangerate-api.com

  1. 参数设置
    参数 说明 示例
    IncomeAmount 收入金额 5000
    IncomeCurrency 收入币种 USD
    TaxCurrency 计税币种 CNY
    TaxRate 税率(%) 10
    Deduction 免征额 5000
  2. 运行效果
    text
    ===== 个人所得税计算器 =====
    收入金额: 5000.00 USD
    计税币种: CNY
    税率: 10.00%
    免征额: 5000.00 CNY
    成功获取汇率: 1 USD = 7.25 CNY
    折算后收入: 36250.00 CNY

应纳税所得额: 31250.00 CNY
应缴个人所得税: 3125.00 CNY
税后收入: 33125.00 CNY
===== 计算完成 =====
技术要点解析

  1. WebRequest网络请求
    使用HTTP GET方法获取实时汇率

JSON响应解析提取目标币种汇率

超时和错误处理机制

  1. 汇率API集成
    支持任意币种对换算

自动处理API响应格式

网络异常时的降级策略

  1. 税务计算逻辑
    应纳税所得额 = 收入 - 免征额

个人所得税 = 应纳税所得额 × 税率

支持负收入自动归零处理

相关文章
|
1天前
|
人工智能 JSON 机器人
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
本文带你零成本玩转OpenClaw:学生认证白嫖6个月阿里云服务器,手把手配置飞书机器人、接入免费/高性价比AI模型(NVIDIA/通义),并打造微信公众号“全自动分身”——实时抓热榜、AI选题拆解、一键发布草稿,5分钟完成热点→文章全流程!
10068 22
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
|
13天前
|
人工智能 安全 Linux
【OpenClaw保姆级图文教程】阿里云/本地部署集成模型Ollama/Qwen3.5/百炼 API 步骤流程及避坑指南
2026年,AI代理工具的部署逻辑已从“单一云端依赖”转向“云端+本地双轨模式”。OpenClaw(曾用名Clawdbot)作为开源AI代理框架,既支持对接阿里云百炼等云端免费API,也能通过Ollama部署本地大模型,完美解决两类核心需求:一是担心云端API泄露核心数据的隐私安全诉求;二是频繁调用导致token消耗过高的成本控制需求。
5813 14
|
20天前
|
人工智能 JavaScript Ubuntu
5分钟上手龙虾AI!OpenClaw部署(阿里云+本地)+ 免费多模型配置保姆级教程(MiniMax、Claude、阿里云百炼)
OpenClaw(昵称“龙虾AI”)作为2026年热门的开源个人AI助手,由PSPDFKit创始人Peter Steinberger开发,核心优势在于“真正执行任务”——不仅能聊天互动,还能自动处理邮件、管理日程、订机票、写代码等,且所有数据本地处理,隐私完全可控。它支持接入MiniMax、Claude、GPT等多类大模型,兼容微信、Telegram、飞书等主流聊天工具,搭配100+可扩展技能,成为兼顾实用性与隐私性的AI工具首选。
22688 119

热门文章

最新文章