Calcular Costo Base Fifo logo

Calcular Costo Base Fifo

Community
elimorals
calcular-costo-base-fifo

Calcula el costo base FIFO (primeras entradas, primeras salidas) por criptoactivo para determinar la ganancia o pérdida de cada venta o permuta en MXN. La LISR no fija método para activos fungibles; FIFO es un criterio común que debe documentarse y aplicarse de forma consistente. Usar cuando el usuario diga costo base, FIFO cripto, costo de adquisición cripto, calcular ganancia por venta de bitcoin, ganancia realizada.

Overview

Publisherelimorals
RepositorySkills_MX
Skill namecalcular-costo-base-fifo
Stars
29
Forks
5
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by elimorals on GitHub. Read the source before you install it.

Installation

Install the Calcular Costo Base Fifo AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/elimorals/Skills_MX/tree/main/cripto-fiscal-mx/skills/calcular-costo-base-fifo
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/elimorals/Skills_MX.git /tmp/Skills_MX
mkdir -p .claude/skills
cp -r /tmp/Skills_MX/cripto-fiscal-mx/skills/calcular-costo-base-fifo .claude/skills/calcular-costo-base-fifo
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Calcular Costo Base Fifo in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Calcular Costo Base Fifo on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Calcular Costo Base Fifo is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Costo base FIFO

La LISR exige "costo comprobado de adquisición" (Art. 121 fr. I) actualizado por INPC (Art. 124), pero no dice cómo identificar unidades fungibles. FIFO es defendible si se documenta y se usa siempre igual. Confianza media: validar con contador.

Reglas:

  • Costo del lote = (valor MXN pagado + comisión) / cantidad recibida. TC del día de la operación (mp_banxico.banxico_get_tc_dof).
  • Permutas y rewards crean lotes nuevos al valor de mercado en MXN del día de recepción.
  • Transferencias entre wallets propias no crean ni consumen lotes.
  • Actualizar el costo por INPC (Art. 124) al calcular la ganancia de cada enajenación (banxico_get_inpc).
  • Las pérdidas se reportan por separado: criterio conservador, no se restan de las ganancias (ver calculadora-isr-cripto-detallada).

Algoritmo

python
def calcular_fifo(operaciones: list[OperacionCripto]) -> dict:
    inventario = {}  # activo → lista de lots (cantidad, costo_unitario_mxn)
    ganancia_realizada = Decimal("0")
    pérdida_realizada = Decimal("0")

    for op in sorted(operaciones, key=lambda x: x.fecha_hora):
        if op.tipo == "compra":
            inventario.setdefault(op.activo_recibido, []).append({
                "cantidad": op.cantidad_recibida,
                "costo_unitario_mxn": (op.valor_mxn_dia + op.fee_mxn) / op.cantidad_recibida
            })
        elif op.tipo == "venta":
            cantidad_a_vender = op.cantidad_dada
            ingreso_total = op.valor_mxn_dia
            costo_total = Decimal("0")

            while cantidad_a_vender > 0 and inventario[op.activo_dado]:
                lot = inventario[op.activo_dado][0]
                if lot["cantidad"] <= cantidad_a_vender:
                    costo_total += lot["cantidad"] * lot["costo_unitario_mxn"]
                    cantidad_a_vender -= lot["cantidad"]
                    inventario[op.activo_dado].pop(0)
                else:
                    costo_total += cantidad_a_vender * lot["costo_unitario_mxn"]
                    lot["cantidad"] -= cantidad_a_vender
                    cantidad_a_vender = Decimal("0")

            ganancia = ingreso_total - costo_total
            if ganancia > 0:
                ganancia_realizada += ganancia
            else:
                pérdida_realizada += abs(ganancia)

    return {
        "ganancia_realizada_mxn": str(ganancia_realizada),
        "perdida_realizada_mxn": str(pérdida_realizada),
        "ganancia_gravable_conservadora_mxn": str(ganancia_realizada),  # pérdidas no restadas
        "inventario_final": inventario
    }

Output

json
{
  "ejercicio": 2026,
  "metodo": "FIFO",
  "operaciones_procesadas": 245,
  "ganancia_realizada_mxn": "45000.00",
  "perdida_realizada_mxn": "12000.00",
  "ganancia_gravable_conservadora_mxn": "45000.00",
  "neto_si_contador_acepta_compensar_mxn": "33000.00",
  "holdings_finales_valor_mxn": "517800.00",
  "ganancia_latente_mxn": "85000.00"
}

Frequently asked questions

What does the Calcular Costo Base Fifo AI skill do?

Calcula el costo base FIFO (primeras entradas, primeras salidas) por criptoactivo para determinar la ganancia o pérdida de cada venta o permuta en MXN. La LISR no fija método para activos fungibles; FIFO es un criterio común que debe documentarse y aplicarse de forma consistente. Usar cuando el usuario diga costo base, FIFO cripto, costo de adquisición cripto, calcular ganancia por venta de bitcoin, ganancia realizada.

Why use Calcular Costo Base Fifo on TypingMind?

Because you install it once and use it with any model. Calcular Costo Base Fifo is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Calcular Costo Base Fifo in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/elimorals/Skills_MX/tree/main/cripto-fiscal-mx/skills/calcular-costo-base-fifo. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Calcular Costo Base Fifo?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Calcular Costo Base Fifo?

As many as you like. As long as a model supports skills, you can use Calcular Costo Base Fifo with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Calcular Costo Base Fifo AI skill free?

Yes. It is published on GitHub by elimorals under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇