Spaces:
Running
Running
atualizacao automatica dos dados da CVM
Browse files- app.js +230 -59
- styles.css +20 -7
app.js
CHANGED
|
@@ -14515,8 +14515,64 @@ const ORDEM_TIT = [['emis_s', 'emissão mais recente', 'desc'], ['valor_fundos',
|
|
| 14515 |
const IDX_TIT = [['todos', 'Todos'], ['DI +', 'DI +'], ['% DI', '% do DI'], ['IPCA', 'IPCA +'], ['IGP-M', 'IGP-M +'],
|
| 14516 |
['PRE', 'Pré']];
|
| 14517 |
|
| 14518 |
-
/**
|
| 14519 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14520 |
const nota = r[campos.nota || 'rating'];
|
| 14521 |
if (!nota) return '<span class="muted">—</span>';
|
| 14522 |
const d = {
|
|
@@ -14525,6 +14581,15 @@ function celulaRating(r, campos = {}) {
|
|
| 14525 |
conferir: r[campos.conferir || 'rating_conferir'], escala: r[campos.escala || 'rating_escala'],
|
| 14526 |
fim: r[campos.fim || 'dt_fim_s'],
|
| 14527 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14528 |
// Nota de mais de 3 anos (ou ja encerrada) sai APAGADA e com o ano ao lado:
|
| 14529 |
// a de 2016 nao pode parecer tao atual quanto a do mes passado.
|
| 14530 |
const ano = d.data ? Number(String(d.data).slice(-4)) : null;
|
|
@@ -14553,7 +14618,18 @@ function ligarBalaoRating() {
|
|
| 14553 |
${d.fim ? `<div class="pr-fim">Encerrada em ${esc(d.fim)} (a agência retirou ou trocou a nota)</div>` : ''}
|
| 14554 |
<div class="pr-fonte">Fonte: ${esc(d.fonte || '—')}</div>
|
| 14555 |
${d.url ? `<a href="${esc(d.url)}" target="_blank" rel="noopener">abrir o documento ↗</a>` : ''}
|
| 14556 |
-
${d.conferir ? `<div class="pr-conf">Como conferir: ${esc(d.conferir)}</div>` : ''}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14557 |
pop.hidden = false;
|
| 14558 |
const b = el.getBoundingClientRect(), w = Math.min(340, window.innerWidth - 24);
|
| 14559 |
pop.style.width = `${w}px`;
|
|
@@ -14626,6 +14702,8 @@ async function pageTitulos() {
|
|
| 14626 |
app.innerHTML = '<div class="empty">Os dados de títulos privados ainda não foram publicados.</div>';
|
| 14627 |
return;
|
| 14628 |
}
|
|
|
|
|
|
|
| 14629 |
for (const r of linhas) {
|
| 14630 |
for (const k of ['taxa_indicativa', 'pct_pu_par', 'duration', 'pu', 'valor_fundos', 'taxa_emissao',
|
| 14631 |
'volume_emissao', 'saldo', 'pu_fundos']) if (r[k] != null) r[k] = Number(r[k]);
|
|
@@ -14684,7 +14762,6 @@ async function pageTitulos() {
|
|
| 14684 |
<input id="buscaTit" type="search" placeholder="código, emissor, devedor ou securitizadora" autocomplete="off" value="${esc(titSt.termo)}">
|
| 14685 |
</section>
|
| 14686 |
<div class="nota-tipo" id="titNotaTipo"></div>
|
| 14687 |
-
<div id="titQuemComprou"></div>
|
| 14688 |
<div class="sub tit-conta" id="titConta"></div>
|
| 14689 |
<div class="tbl-wrap" id="tblTit"></div>
|
| 14690 |
<div id="maisTit"></div>
|
|
@@ -14707,44 +14784,6 @@ async function pageTitulos() {
|
|
| 14707 |
<b>LCA</b>: só o que os fundos declaram, que é pouco — o fundo não tem a isenção de IR que faz o
|
| 14708 |
papel valer a pena. <b>LCI</b>: ver a aba.</div>`;
|
| 14709 |
|
| 14710 |
-
// QUEM FICOU COM AS OFERTAS nos ultimos 12 meses, os tres tipos numa TABELA
|
| 14711 |
-
// (18/11/2026: "colocar como tabelinha"). Soma dos quadros dos anuncios de
|
| 14712 |
-
// encerramento, em % da quantidade. A linha do tipo aberto fica destacada.
|
| 14713 |
-
const quemComprou = async () => {
|
| 14714 |
-
const el = document.getElementById('titQuemComprou');
|
| 14715 |
-
if (!el) return;
|
| 14716 |
-
const rs = await q(`
|
| 14717 |
-
select case when valor_mobiliario ilike 'Deb%' then 'Debênture'
|
| 14718 |
-
when valor_mobiliario ilike '%Imobili%' then 'CRI'
|
| 14719 |
-
when valor_mobiliario ilike '%Agroneg%' then 'CRA' end tipo,
|
| 14720 |
-
count(*) n_of, sum(valor_registrado) valor, sum(q_fundos) f, sum(q_inst_fin) b, sum(q_pf) pf,
|
| 14721 |
-
sum(q_previdencia + q_seguradoras + q_estrangeiros + q_pj + q_clubes) o
|
| 14722 |
-
from titulos_ofertas
|
| 14723 |
-
where dt_registro >= current_date - interval 365 day
|
| 14724 |
-
and (valor_mobiliario ilike 'Deb%' or valor_mobiliario ilike 'Certificados de Receb%')
|
| 14725 |
-
group by 1 having tipo is not null`).catch(() => []);
|
| 14726 |
-
if (!rs.length) { el.innerHTML = ''; return; }
|
| 14727 |
-
const ordem = ['Debênture', 'CRI', 'CRA'];
|
| 14728 |
-
rs.sort((a, b) => ordem.indexOf(a.tipo) - ordem.indexOf(b.tipo));
|
| 14729 |
-
const nome = { 'Debênture': 'Debêntures', CRI: 'CRI', CRA: 'CRA' };
|
| 14730 |
-
const pc = (v, t) => (t ? `${nf(100 * (Number(v) || 0) / t, 0)}%` : '—');
|
| 14731 |
-
el.innerHTML = `<div class="tit-quem-tab">
|
| 14732 |
-
<div class="tit-quem-h">Quem ficou com as ofertas nos últimos 12 meses <span class="muted">· % da quantidade emitida</span></div>
|
| 14733 |
-
<div class="tbl-wrap"><table class="tbl-quem"><thead><tr><th class="l">Tipo</th><th class="num">Ofertas</th>
|
| 14734 |
-
<th class="num" title="Fundos de investimento">Fundos</th><th class="num" title="Bancos e corretoras">Bancos</th>
|
| 14735 |
-
<th class="num" title="Pessoas físicas">PF</th><th class="num">Demais</th></tr></thead>
|
| 14736 |
-
<tbody>${rs.map(r => {
|
| 14737 |
-
const t = ['f', 'b', 'pf', 'o'].reduce((acc, k) => acc + (Number(r[k]) || 0), 0);
|
| 14738 |
-
return `<tr class="${r.tipo === titSt.tipo ? 'on' : ''}"><th class="l">${nome[r.tipo]}</th>
|
| 14739 |
-
<td class="num mono">${nf(Number(r.n_of), 0)}<div class="nome-s">${brl(Number(r.valor), { sinal: false })}</div></td>
|
| 14740 |
-
<td class="num mono">${pc(r.f, t)}</td><td class="num mono">${pc(r.b, t)}</td>
|
| 14741 |
-
<td class="num mono">${pc(r.pf, t)}</td><td class="num mono">${pc(r.o, t)}</td></tr>`;
|
| 14742 |
-
}).join('')}</tbody></table></div>
|
| 14743 |
-
<div class="nota-graf">Quadro "dados finais de distribuição" do anúncio de encerramento, como a CVM o publica. Bancos e
|
| 14744 |
-
corretoras (Bancos) incluem o que o coordenador ficou na garantia firme; PF = pessoas físicas; demais = previdência, seguradoras, estrangeiros,
|
| 14745 |
-
outras empresas e clubes. O detalhe de cada oferta está na página do título.</div></div>`;
|
| 14746 |
-
};
|
| 14747 |
-
|
| 14748 |
// Nota do tipo escolhido, para o que nao tem lista completa.
|
| 14749 |
const notaTipo = () => {
|
| 14750 |
const el = document.getElementById('titNotaTipo');
|
|
@@ -14825,7 +14864,7 @@ async function pageTitulos() {
|
|
| 14825 |
<td class="num mono" data-rot="% PU par">${r.pct_pu_par == null ? '—' : `<span class="${r.pct_pu_par < 95 ? 'neg' : ''}">${nf(r.pct_pu_par, 2)}%</span>`}</td>
|
| 14826 |
<td class="num mono" data-rot="Duration">${r.duration == null ? '—' : nf(r.duration, 2)}</td>`}
|
| 14827 |
<td class="num mono" data-rot="Vencimento">${r.venc_s ? dataBR(r.venc_s) : '—'}</td>
|
| 14828 |
-
<td class="l" data-rot="Rating">${celulaRating(r)}</td>
|
| 14829 |
<td class="num mono" data-rot="Fundos">${r.n_fundos ? nf(r.n_fundos, 0) : '—'}</td>
|
| 14830 |
<td class="num mono" data-rot="Nos fundos">${r.valor_fundos ? brl(r.valor_fundos, { sinal: false }) : '—'}</td>
|
| 14831 |
</tr>`).join('')}</tbody></table>`;
|
|
@@ -14849,7 +14888,6 @@ async function pageTitulos() {
|
|
| 14849 |
document.getElementById('ctlTitPreco').hidden = titSt.tipo !== 'Debênture';
|
| 14850 |
document.getElementById('ctlTitCart').hidden = titSt.tipo === 'LCA' || titSt.tipo === 'LCI';
|
| 14851 |
notaTipo();
|
| 14852 |
-
quemComprou();
|
| 14853 |
};
|
| 14854 |
ligarSeg('segTitTipo', v => { titSt.tipo = v; soDeb(); de(); });
|
| 14855 |
soDeb();
|
|
@@ -14899,7 +14937,7 @@ async function pageTitulo(codigo) {
|
|
| 14899 |
// So o indicativo da ANBIMA vai ao grafico (os negocios do SND sairam em 17/11/2026).
|
| 14900 |
deb ? q(`select strftime(dt, '%Y-%m-%d') d, taxa_indicativa, pu, pct_pu_par, duration
|
| 14901 |
from titulos_precos where codigo = '${c}' and fonte = 'anbima' order by dt`) : [],
|
| 14902 |
-
q(`select agencia, rating_orig, rating, escala, strftime(dt_rating, '%Y-%m-%d') d,
|
| 14903 |
strftime(dt_fim, '%Y-%m-%d') f, fonte, url, como_conferir
|
| 14904 |
from titulos_ratings where codigo = '${c}' order by dt_rating desc nulls last`),
|
| 14905 |
// CRI/CRA: o PU que os fundos declaram, mes a mes (mediana, minimo e maximo).
|
|
@@ -14941,7 +14979,7 @@ async function pageTitulo(codigo) {
|
|
| 14941 |
: `mediana de ${nf(Number(r.n_pu_fundos), 0)} fundo(s), ${mesAnoBR(r.pu_s)}`) : ''}
|
| 14942 |
${sec ? cartao('Integralizado', r.volume_emissao == null ? '—' : brl(Number(r.volume_emissao), { sinal: false }),
|
| 14943 |
'como declarado pela securitizadora') : ''}
|
| 14944 |
-
<div class="card"><div class="card-l">Rating</div><div class="card-v tit-v">${celulaRating(r)}</div>
|
| 14945 |
<div class="card-s">${r.rating ? `${esc(r.rating_agencia || '')}${r.dt_rating_s ? ` · ${r.dt_rating_s}` : ''}` : 'nenhum com fonte pública'}</div></div>
|
| 14946 |
${deb ? cartao('Volume emitido', r.volume_emissao == null ? '—' : brl(Number(r.volume_emissao), { sinal: false }),
|
| 14947 |
r.saldo ? `saldo hoje ${brl(Number(r.saldo), { sinal: false })}` : '') : ''}
|
|
@@ -15229,19 +15267,152 @@ async function quemTemTitulo(r) {
|
|
| 15229 |
if (!document.getElementById('titQuem')) return;
|
| 15230 |
if (!rows.length) { el.innerHTML = '<div class="empty">Nenhum fundo declarou este título nos últimos 12 meses de carteira.</div>'; return; }
|
| 15231 |
const atuais = rows.filter(x => x.atual);
|
| 15232 |
-
|
| 15233 |
-
|
| 15234 |
-
|
| 15235 |
-
|
| 15236 |
-
|
| 15237 |
-
|
| 15238 |
-
|
| 15239 |
-
|
| 15240 |
-
|
| 15241 |
-
|
| 15242 |
-
|
| 15243 |
-
|
| 15244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15245 |
}
|
| 15246 |
|
| 15247 |
|
|
|
|
| 14515 |
const IDX_TIT = [['todos', 'Todos'], ['DI +', 'DI +'], ['% DI', '% do DI'], ['IPCA', 'IPCA +'], ['IGP-M', 'IGP-M +'],
|
| 14516 |
['PRE', 'Pré']];
|
| 14517 |
|
| 14518 |
+
/** HISTORICO DE RATINGS de todos os titulos, por codigo, o mais recente primeiro.
|
| 14519 |
+
* `titulos_ratings` e pequeno (~2 mil linhas): vem inteiro, uma vez por visita,
|
| 14520 |
+
* e alimenta a evolucao no balao da lista. */
|
| 14521 |
+
let _histRatP = null;
|
| 14522 |
+
function histRatings() {
|
| 14523 |
+
if (!_histRatP) {
|
| 14524 |
+
_histRatP = q(`select codigo, agencia, rating_orig, "rank" rk, escala,
|
| 14525 |
+
strftime(dt_rating, '%Y-%m-%d') d, strftime(dt_fim, '%Y-%m-%d') f
|
| 14526 |
+
from titulos_ratings order by codigo, dt_rating desc nulls last`)
|
| 14527 |
+
.then(rs => {
|
| 14528 |
+
const m = new Map();
|
| 14529 |
+
for (const x of rs) {
|
| 14530 |
+
if (!m.has(x.codigo)) m.set(x.codigo, []);
|
| 14531 |
+
m.get(x.codigo).push(x);
|
| 14532 |
+
}
|
| 14533 |
+
return m;
|
| 14534 |
+
})
|
| 14535 |
+
.catch(e => { console.warn('historico de ratings:', e.message); _histRatP = null; return new Map(); });
|
| 14536 |
+
}
|
| 14537 |
+
return _histRatP;
|
| 14538 |
+
}
|
| 14539 |
+
|
| 14540 |
+
/** Nome curto da agencia, e o MESMO para as grafias de uma casa so: a seta de
|
| 14541 |
+
* elevacao/rebaixamento compara com a nota anterior da mesma agencia, e
|
| 14542 |
+
* "Fitch Atlantic Ratings" e "Fitch Ratings" sao a mesma linhagem. */
|
| 14543 |
+
function agCurta(a) {
|
| 14544 |
+
const t = String(a || '').trim();
|
| 14545 |
+
if (/fitch/i.test(t)) return 'Fitch';
|
| 14546 |
+
if (/standard|s\s*&\s*p/i.test(t)) return 'S&P';
|
| 14547 |
+
if (/moody/i.test(t)) return "Moody's";
|
| 14548 |
+
if (/austin/i.test(t)) return 'Austin';
|
| 14549 |
+
if (/liberum/i.test(t)) return 'Liberum';
|
| 14550 |
+
if (/atlantic/i.test(t)) return 'Atlantic';
|
| 14551 |
+
return t.replace(/\s+ratings?$/i, '').replace(/\s+rating$/i, '') || '—';
|
| 14552 |
+
}
|
| 14553 |
+
|
| 14554 |
+
/** Evolucao: [data, agencia, nota, encerrada em, movimento], a mais recente
|
| 14555 |
+
* primeiro. O movimento so existe contra a nota ANTERIOR DA MESMA AGENCIA e na
|
| 14556 |
+
* mesma escala (nacional x global tem letras que nao se comparam). */
|
| 14557 |
+
function evolucaoRating(hist) {
|
| 14558 |
+
const asc = hist.filter(x => x.d).sort((a, b) => (a.d < b.d ? -1 : a.d > b.d ? 1 : 0));
|
| 14559 |
+
const ult = {};
|
| 14560 |
+
const out = asc.map(x => {
|
| 14561 |
+
const ag = agCurta(x.agencia);
|
| 14562 |
+
const ch = `${ag}|${x.escala || ''}`;
|
| 14563 |
+
const rk = x.rk == null ? null : Number(x.rk);
|
| 14564 |
+
const ant = ult[ch];
|
| 14565 |
+
const mov = ant == null || rk == null ? '' : rk < ant ? 'up' : rk > ant ? 'down' : '';
|
| 14566 |
+
if (rk != null) ult[ch] = rk;
|
| 14567 |
+
return [dataBR(x.d), ag, x.rating_orig, x.f ? dataBR(x.f) : null, mov];
|
| 14568 |
+
});
|
| 14569 |
+
return out.reverse();
|
| 14570 |
+
}
|
| 14571 |
+
|
| 14572 |
+
/** Celula de rating: a nota, e a fonte num balao ao passar o mouse. Com `hist`
|
| 14573 |
+
* (as notas do titulo, de `histRatings` ou da propria pagina), o balao mostra
|
| 14574 |
+
* tambem a evolucao. */
|
| 14575 |
+
function celulaRating(r, campos = {}, hist = null) {
|
| 14576 |
const nota = r[campos.nota || 'rating'];
|
| 14577 |
if (!nota) return '<span class="muted">—</span>';
|
| 14578 |
const d = {
|
|
|
|
| 14581 |
conferir: r[campos.conferir || 'rating_conferir'], escala: r[campos.escala || 'rating_escala'],
|
| 14582 |
fim: r[campos.fim || 'dt_fim_s'],
|
| 14583 |
};
|
| 14584 |
+
if (hist && hist.length) {
|
| 14585 |
+
// Sem nota vigente, o ETL mostra a mais recente ja encerrada: o "encerrada
|
| 14586 |
+
// em" vem do historico, porque o `titulos_dim` nao carrega a data de fim.
|
| 14587 |
+
if (!d.fim) {
|
| 14588 |
+
const igual = hist.find(x => x.f && x.rating_orig === nota && (!d.data || (x.d && dataBR(x.d) === d.data)));
|
| 14589 |
+
if (igual) d.fim = dataBR(igual.f);
|
| 14590 |
+
}
|
| 14591 |
+
if (hist.length > 1) d.h = evolucaoRating(hist);
|
| 14592 |
+
}
|
| 14593 |
// Nota de mais de 3 anos (ou ja encerrada) sai APAGADA e com o ano ao lado:
|
| 14594 |
// a de 2016 nao pode parecer tao atual quanto a do mes passado.
|
| 14595 |
const ano = d.data ? Number(String(d.data).slice(-4)) : null;
|
|
|
|
| 14618 |
${d.fim ? `<div class="pr-fim">Encerrada em ${esc(d.fim)} (a agência retirou ou trocou a nota)</div>` : ''}
|
| 14619 |
<div class="pr-fonte">Fonte: ${esc(d.fonte || '—')}</div>
|
| 14620 |
${d.url ? `<a href="${esc(d.url)}" target="_blank" rel="noopener">abrir o documento ↗</a>` : ''}
|
| 14621 |
+
${d.conferir ? `<div class="pr-conf">Como conferir: ${esc(d.conferir)}</div>` : ''}
|
| 14622 |
+
${Array.isArray(d.h) && d.h.length ? `<div class="pr-hist">
|
| 14623 |
+
<div class="pr-hist-t">Evolução do rating <span class="muted">· ${nf(d.h.length, 0)} notas, a mais recente primeiro</span></div>
|
| 14624 |
+
<table class="pr-tab"><tbody>${d.h.slice(0, 12).map(([dt, ag, nt, fim, mov]) => `
|
| 14625 |
+
<tr class="${fim ? 'pr-enc' : ''}"${fim ? ` title="encerrada em ${esc(fim)}"` : ''}>
|
| 14626 |
+
<td class="mono">${esc(dt)}</td><td>${esc(ag)}</td>
|
| 14627 |
+
<td class="mono">${esc(nt)}${mov === 'up' ? ' <span class="pos" title="elevação">▲</span>'
|
| 14628 |
+
: mov === 'down' ? ' <span class="neg" title="rebaixamento">▼</span>' : ''}</td></tr>`).join('')}
|
| 14629 |
+
</tbody></table>
|
| 14630 |
+
${d.h.length > 12 ? `<div class="muted pr-mais">e mais ${nf(d.h.length - 12, 0)} anteriores, na página do título</div>` : ''}
|
| 14631 |
+
<div class="muted pr-mais">▲ elevação e ▼ rebaixamento contra a nota anterior da mesma agência; em cinza, as encerradas.</div>
|
| 14632 |
+
</div>` : ''}`;
|
| 14633 |
pop.hidden = false;
|
| 14634 |
const b = el.getBoundingClientRect(), w = Math.min(340, window.innerWidth - 24);
|
| 14635 |
pop.style.width = `${w}px`;
|
|
|
|
| 14702 |
app.innerHTML = '<div class="empty">Os dados de títulos privados ainda não foram publicados.</div>';
|
| 14703 |
return;
|
| 14704 |
}
|
| 14705 |
+
// Evolucao do rating no balao: o historico inteiro vem junto (e pequeno).
|
| 14706 |
+
const histRat = await histRatings();
|
| 14707 |
for (const r of linhas) {
|
| 14708 |
for (const k of ['taxa_indicativa', 'pct_pu_par', 'duration', 'pu', 'valor_fundos', 'taxa_emissao',
|
| 14709 |
'volume_emissao', 'saldo', 'pu_fundos']) if (r[k] != null) r[k] = Number(r[k]);
|
|
|
|
| 14762 |
<input id="buscaTit" type="search" placeholder="código, emissor, devedor ou securitizadora" autocomplete="off" value="${esc(titSt.termo)}">
|
| 14763 |
</section>
|
| 14764 |
<div class="nota-tipo" id="titNotaTipo"></div>
|
|
|
|
| 14765 |
<div class="sub tit-conta" id="titConta"></div>
|
| 14766 |
<div class="tbl-wrap" id="tblTit"></div>
|
| 14767 |
<div id="maisTit"></div>
|
|
|
|
| 14784 |
<b>LCA</b>: só o que os fundos declaram, que é pouco — o fundo não tem a isenção de IR que faz o
|
| 14785 |
papel valer a pena. <b>LCI</b>: ver a aba.</div>`;
|
| 14786 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14787 |
// Nota do tipo escolhido, para o que nao tem lista completa.
|
| 14788 |
const notaTipo = () => {
|
| 14789 |
const el = document.getElementById('titNotaTipo');
|
|
|
|
| 14864 |
<td class="num mono" data-rot="% PU par">${r.pct_pu_par == null ? '—' : `<span class="${r.pct_pu_par < 95 ? 'neg' : ''}">${nf(r.pct_pu_par, 2)}%</span>`}</td>
|
| 14865 |
<td class="num mono" data-rot="Duration">${r.duration == null ? '—' : nf(r.duration, 2)}</td>`}
|
| 14866 |
<td class="num mono" data-rot="Vencimento">${r.venc_s ? dataBR(r.venc_s) : '—'}</td>
|
| 14867 |
+
<td class="l" data-rot="Rating">${celulaRating(r, {}, histRat.get(r.codigo))}</td>
|
| 14868 |
<td class="num mono" data-rot="Fundos">${r.n_fundos ? nf(r.n_fundos, 0) : '—'}</td>
|
| 14869 |
<td class="num mono" data-rot="Nos fundos">${r.valor_fundos ? brl(r.valor_fundos, { sinal: false }) : '—'}</td>
|
| 14870 |
</tr>`).join('')}</tbody></table>`;
|
|
|
|
| 14888 |
document.getElementById('ctlTitPreco').hidden = titSt.tipo !== 'Debênture';
|
| 14889 |
document.getElementById('ctlTitCart').hidden = titSt.tipo === 'LCA' || titSt.tipo === 'LCI';
|
| 14890 |
notaTipo();
|
|
|
|
| 14891 |
};
|
| 14892 |
ligarSeg('segTitTipo', v => { titSt.tipo = v; soDeb(); de(); });
|
| 14893 |
soDeb();
|
|
|
|
| 14937 |
// So o indicativo da ANBIMA vai ao grafico (os negocios do SND sairam em 17/11/2026).
|
| 14938 |
deb ? q(`select strftime(dt, '%Y-%m-%d') d, taxa_indicativa, pu, pct_pu_par, duration
|
| 14939 |
from titulos_precos where codigo = '${c}' and fonte = 'anbima' order by dt`) : [],
|
| 14940 |
+
q(`select agencia, rating_orig, rating, "rank" rk, escala, strftime(dt_rating, '%Y-%m-%d') d,
|
| 14941 |
strftime(dt_fim, '%Y-%m-%d') f, fonte, url, como_conferir
|
| 14942 |
from titulos_ratings where codigo = '${c}' order by dt_rating desc nulls last`),
|
| 14943 |
// CRI/CRA: o PU que os fundos declaram, mes a mes (mediana, minimo e maximo).
|
|
|
|
| 14979 |
: `mediana de ${nf(Number(r.n_pu_fundos), 0)} fundo(s), ${mesAnoBR(r.pu_s)}`) : ''}
|
| 14980 |
${sec ? cartao('Integralizado', r.volume_emissao == null ? '—' : brl(Number(r.volume_emissao), { sinal: false }),
|
| 14981 |
'como declarado pela securitizadora') : ''}
|
| 14982 |
+
<div class="card"><div class="card-l">Rating</div><div class="card-v tit-v">${celulaRating(r, {}, ratings)}</div>
|
| 14983 |
<div class="card-s">${r.rating ? `${esc(r.rating_agencia || '')}${r.dt_rating_s ? ` · ${r.dt_rating_s}` : ''}` : 'nenhum com fonte pública'}</div></div>
|
| 14984 |
${deb ? cartao('Volume emitido', r.volume_emissao == null ? '—' : brl(Number(r.volume_emissao), { sinal: false }),
|
| 14985 |
r.saldo ? `saldo hoje ${brl(Number(r.saldo), { sinal: false })}` : '') : ''}
|
|
|
|
| 15267 |
if (!document.getElementById('titQuem')) return;
|
| 15268 |
if (!rows.length) { el.innerHTML = '<div class="empty">Nenhum fundo declarou este título nos últimos 12 meses de carteira.</div>'; return; }
|
| 15269 |
const atuais = rows.filter(x => x.atual);
|
| 15270 |
+
for (const x of rows) { x.valor = Number(x.valor); x.pct = x.pct == null ? null : Number(x.pct); }
|
| 15271 |
+
|
| 15272 |
+
// ORDENAVEL PELO CABECALHO (18/11/2026). Quem ainda tem fica sempre em cima e
|
| 15273 |
+
// quem saiu sempre embaixo: misturar as duas faixas poria uma posicao de um
|
| 15274 |
+
// ano atras no meio das de hoje. A ordem escolhida vale dentro de cada faixa.
|
| 15275 |
+
const COLS = [
|
| 15276 |
+
{ k: 'nome', t: 'Fundo', l: true, v: x => (x.nome || x.cnpj || '').toLowerCase() },
|
| 15277 |
+
{ k: 'gestora', t: 'Gestora', l: true, v: x => (x.grupo_nome || '').toLowerCase() },
|
| 15278 |
+
{ k: 'valor', t: 'Posição', v: x => x.valor },
|
| 15279 |
+
{ k: 'pct', t: '% do PL', v: x => x.pct },
|
| 15280 |
+
{ k: 'desde', t: 'Desde', v: x => x.desde },
|
| 15281 |
+
{ k: 'ult', t: 'Último mês', v: x => x.ult },
|
| 15282 |
+
];
|
| 15283 |
+
const ord = { k: 'valor', dir: 'desc' };
|
| 15284 |
+
const desenhar = () => {
|
| 15285 |
+
const col = COLS.find(c => c.k === ord.k);
|
| 15286 |
+
const sinal = ord.dir === 'desc' ? -1 : 1;
|
| 15287 |
+
const lista = [...rows].sort((a, b) => {
|
| 15288 |
+
if (a.atual !== b.atual) return a.atual ? -1 : 1;
|
| 15289 |
+
const va = col.v(a), vb = col.v(b);
|
| 15290 |
+
if (va == null && vb == null) return 0;
|
| 15291 |
+
if (va == null) return 1; // sem numero vai para o fim nas duas direcoes
|
| 15292 |
+
if (vb == null) return -1;
|
| 15293 |
+
return va < vb ? -sinal : va > vb ? sinal : 0;
|
| 15294 |
+
}).slice(0, 200);
|
| 15295 |
+
el.innerHTML = `<div class="sub">${nf(atuais.length, 0)} fundo(s) com o título na carteira mais recente;
|
| 15296 |
+
${nf(rows.length - atuais.length, 0)} tiveram e não declaram mais. Clique no cabeçalho para ordenar.</div>
|
| 15297 |
+
<div class="tbl-wrap"><table class="tbl-quem-tem"><thead><tr>${COLS.map(c => `
|
| 15298 |
+
<th class="${c.l ? 'l' : 'num'} sortable" data-c="${c.k}">${c.t}${ord.k === c.k
|
| 15299 |
+
? `<span class="arrow">${ord.dir === 'desc' ? '▼' : '▲'}</span>` : ''}</th>`).join('')}<th></th></tr></thead>
|
| 15300 |
+
<tbody>${lista.map(x => `<tr class="${x.atual ? '' : 'muted'}">
|
| 15301 |
+
<td class="l"><a href="#/fundo/${esc(x.cnpj)}">${esc(x.nome || x.cnpj)}</a></td>
|
| 15302 |
+
<td class="l">${x.grupo_id != null ? `<a href="#/gestora/${x.grupo_id}">${esc(x.grupo_nome || '')}</a>` : ''}</td>
|
| 15303 |
+
<td class="num mono">${brl(x.valor, { sinal: false })}</td>
|
| 15304 |
+
<td class="num mono">${x.pct == null ? '—' : `${nf(x.pct, 2)}%`}</td>
|
| 15305 |
+
<td class="num mono">${mesAnoBR(x.desde)}</td><td class="num mono">${mesAnoBR(x.ult)}</td>
|
| 15306 |
+
<td class="l"><button type="button" class="btn-hist" data-cnpj="${esc(x.cnpj)}"
|
| 15307 |
+
data-nome="${esc(x.nome || x.cnpj)}" aria-expanded="false">Histórico</button></td></tr>`).join('')}
|
| 15308 |
+
</tbody></table></div>
|
| 15309 |
+
<div class="nota-rodape">Carteiras declaradas à CVM (CDA). Mês recente fica de fora enquanto a CVM
|
| 15310 |
+
permite ao fundo omitir posição; em cinza, quem teve e não declara mais.</div>`;
|
| 15311 |
+
el.querySelectorAll('th.sortable').forEach(th => th.onclick = () => {
|
| 15312 |
+
if (ord.k === th.dataset.c) ord.dir = ord.dir === 'desc' ? 'asc' : 'desc';
|
| 15313 |
+
else { ord.k = th.dataset.c; ord.dir = COLS.find(c => c.k === th.dataset.c).l ? 'asc' : 'desc'; }
|
| 15314 |
+
desenhar();
|
| 15315 |
+
});
|
| 15316 |
+
el.querySelectorAll('.btn-hist').forEach(b => b.onclick = () => abrirHistoricoQuemTem(b, c));
|
| 15317 |
+
};
|
| 15318 |
+
desenhar();
|
| 15319 |
+
}
|
| 15320 |
+
|
| 15321 |
+
/** HISTORICO DE UM FUNDO NO TITULO: a linha logo abaixo abre um grafico com a
|
| 15322 |
+
* posicao (R$, barras) em cima e o % do PL (linha) embaixo, no mesmo eixo de
|
| 15323 |
+
* meses e com um cursor so. Dois paineis e nao dois eixos y no mesmo plano:
|
| 15324 |
+
* escalas sobrepostas fazem o olho ler cruzamentos que nao significam nada.
|
| 15325 |
+
* Mes sem declaracao fica vazio, e nao ligado ao vizinho. */
|
| 15326 |
+
async function abrirHistoricoQuemTem(btn, codigoSql) {
|
| 15327 |
+
const tr = btn.closest('tr');
|
| 15328 |
+
const prox = tr.nextElementSibling;
|
| 15329 |
+
if (prox && prox.classList.contains('hist-linha')) {
|
| 15330 |
+
prox.remove();
|
| 15331 |
+
btn.setAttribute('aria-expanded', 'false');
|
| 15332 |
+
btn.classList.remove('on');
|
| 15333 |
+
return;
|
| 15334 |
+
}
|
| 15335 |
+
btn.setAttribute('aria-expanded', 'true');
|
| 15336 |
+
btn.classList.add('on');
|
| 15337 |
+
const nCols = tr.children.length;
|
| 15338 |
+
const lin = document.createElement('tr');
|
| 15339 |
+
lin.className = 'hist-linha';
|
| 15340 |
+
lin.innerHTML = `<td colspan="${nCols}"><div class="hist-caixa"><div class="loading">consultando…</div></div></td>`;
|
| 15341 |
+
tr.after(lin);
|
| 15342 |
+
const caixa = lin.querySelector('.hist-caixa');
|
| 15343 |
+
const cnpj = sqlTxt(btn.dataset.cnpj);
|
| 15344 |
+
let rs;
|
| 15345 |
+
try {
|
| 15346 |
+
rs = await q(`
|
| 15347 |
+
with p as (
|
| 15348 |
+
select 'a' src, dt_ref, sum(valor) valor, sum(pct_pl) pct from ativos_fundo
|
| 15349 |
+
where ticker = '${codigoSql}' and cnpj = '${cnpj}' group by 1, 2
|
| 15350 |
+
union all
|
| 15351 |
+
select 't' src, dt_ref, sum(valor) valor, sum(pct_pl) pct from titulos_fundo
|
| 15352 |
+
where codigo = '${codigoSql}' and cnpj = '${cnpj}' group by 1, 2)
|
| 15353 |
+
select strftime(dt_ref, '%Y-%m') m, max(valor) valor, max(pct) pct
|
| 15354 |
+
from p group by dt_ref order by dt_ref`);
|
| 15355 |
+
} catch (e) {
|
| 15356 |
+
caixa.innerHTML = `<div class="empty">Não consegui ler o histórico: ${esc(e.message)}</div>`;
|
| 15357 |
+
return;
|
| 15358 |
+
}
|
| 15359 |
+
if (!lin.isConnected) return;
|
| 15360 |
+
if (!rs.length) { caixa.innerHTML = '<div class="empty">Sem histórico deste fundo no título.</div>'; return; }
|
| 15361 |
+
// Todos os meses entre o primeiro e o ultimo, para o buraco aparecer.
|
| 15362 |
+
const porMes = Object.fromEntries(rs.map(r => [r.m, r]));
|
| 15363 |
+
const meses = [];
|
| 15364 |
+
let [a, m] = rs[0].m.split('-').map(Number);
|
| 15365 |
+
const [aF, mF] = rs[rs.length - 1].m.split('-').map(Number);
|
| 15366 |
+
while (a < aF || (a === aF && m <= mF)) {
|
| 15367 |
+
meses.push(`${a}-${String(m).padStart(2, '0')}`);
|
| 15368 |
+
m += 1; if (m > 12) { m = 1; a += 1; }
|
| 15369 |
+
}
|
| 15370 |
+
const val = meses.map(k => (porMes[k] ? Number(porMes[k].valor) : null));
|
| 15371 |
+
const pct = meses.map(k => (porMes[k] && porMes[k].pct != null ? Number(porMes[k].pct) : null));
|
| 15372 |
+
const rotMes = k => `${'jan fev mar abr mai jun jul ago set out nov dez'.split(' ')[Number(k.slice(5, 7)) - 1]}/${k.slice(2, 4)}`;
|
| 15373 |
+
caixa.innerHTML = `<div class="hist-tit">${esc(btn.dataset.nome)} <span class="muted">· ${nf(rs.length, 0)} mês(es) com o título</span></div>
|
| 15374 |
+
<div class="chart chart-hist"></div>
|
| 15375 |
+
<div class="nota-graf">Em cima, a posição declarada (R$); embaixo, quanto ela pesa no patrimônio do fundo.
|
| 15376 |
+
Mês em branco: o fundo não declarou o título naquele mês.</div>`;
|
| 15377 |
+
const g = echarts.init(caixa.querySelector('.chart-hist'));
|
| 15378 |
+
const eixoX = (i, rot) => ({
|
| 15379 |
+
type: 'category', data: meses, gridIndex: i, boundaryGap: true,
|
| 15380 |
+
axisLine: { lineStyle: { color: TEMA.regua } }, axisTick: { show: false },
|
| 15381 |
+
axisLabel: rot ? { color: TEMA.tinta3, fontSize: 10, fontFamily: TEMA.mono, hideOverlap: true, formatter: rotMes }
|
| 15382 |
+
: { show: false },
|
| 15383 |
+
});
|
| 15384 |
+
const eixoY = (i, fmt) => ({
|
| 15385 |
+
type: 'value', gridIndex: i, splitNumber: 3, min: 0,
|
| 15386 |
+
splitLine: { lineStyle: { color: TEMA.reguaFina } },
|
| 15387 |
+
axisLabel: { color: TEMA.tinta3, fontSize: 10, fontFamily: TEMA.mono, formatter: fmt },
|
| 15388 |
+
});
|
| 15389 |
+
const titulo = (txt, top) => ({ text: txt, top, left: 0,
|
| 15390 |
+
textStyle: { color: TEMA.tinta3, fontSize: 11, fontWeight: 600, fontFamily: TEMA.mono } });
|
| 15391 |
+
g.setOption({
|
| 15392 |
+
backgroundColor: 'transparent',
|
| 15393 |
+
title: [titulo('POSIÇÃO (R$)', 0), titulo('% DO PL DO FUNDO', '53%')],
|
| 15394 |
+
grid: [{ left: 70, right: 16, top: 22, height: '36%' }, { left: 70, right: 16, top: '62%', bottom: 28 }],
|
| 15395 |
+
axisPointer: { link: [{ xAxisIndex: 'all' }] },
|
| 15396 |
+
tooltip: {
|
| 15397 |
+
trigger: 'axis', confine: true, backgroundColor: TEMA.branco, borderColor: TEMA.regua, borderWidth: 1,
|
| 15398 |
+
textStyle: { color: TEMA.tinta, fontSize: 12, fontFamily: TEMA.mono },
|
| 15399 |
+
extraCssText: 'box-shadow:0 6px 18px rgba(51,48,46,.14);border-radius:0',
|
| 15400 |
+
formatter: ps => {
|
| 15401 |
+
const k = ps[0].axisValue;
|
| 15402 |
+
const r = porMes[k];
|
| 15403 |
+
return `<b>${rotMes(k)}</b><br>${r ? `posição ${brl(Number(r.valor), { sinal: false })}<br>${
|
| 15404 |
+
r.pct == null ? '% do PL não declarado' : `${nf(Number(r.pct), 2)}% do PL`}` : 'não declarado'}`;
|
| 15405 |
+
},
|
| 15406 |
+
},
|
| 15407 |
+
xAxis: [eixoX(0, false), eixoX(1, true)],
|
| 15408 |
+
yAxis: [eixoY(0, v => brl(v, { sinal: false })), eixoY(1, v => `${nf(v, 2)}%`)],
|
| 15409 |
+
series: [
|
| 15410 |
+
{ name: 'Posição', type: 'bar', xAxisIndex: 0, yAxisIndex: 0, data: val, barMaxWidth: 16,
|
| 15411 |
+
itemStyle: { color: TEMA.teal, borderRadius: [4, 4, 0, 0] } },
|
| 15412 |
+
{ name: '% do PL', type: 'line', xAxisIndex: 1, yAxisIndex: 1, data: pct, connectNulls: false,
|
| 15413 |
+
showSymbol: true, symbolSize: 8, lineStyle: { width: 2 }, color: TEMA.tinta },
|
| 15414 |
+
],
|
| 15415 |
+
});
|
| 15416 |
}
|
| 15417 |
|
| 15418 |
|
styles.css
CHANGED
|
@@ -2689,10 +2689,23 @@ tr:hover .sob-x { opacity: 1; }
|
|
| 2689 |
.tit-quem .ib-nome { grid-column: 1 / -1; }
|
| 2690 |
}
|
| 2691 |
|
| 2692 |
-
|
| 2693 |
-
|
| 2694 |
-
|
| 2695 |
-
.
|
| 2696 |
-
.
|
| 2697 |
-
.
|
| 2698 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2689 |
.tit-quem .ib-nome { grid-column: 1 / -1; }
|
| 2690 |
}
|
| 2691 |
|
| 2692 |
+
|
| 2693 |
+
/* Evolucao do rating no balao (18/11/2026). */
|
| 2694 |
+
.pr-hist { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--regua-fina); }
|
| 2695 |
+
.pr-hist-t { font-size: 11.5px; font-weight: 600; margin-bottom: 4px; }
|
| 2696 |
+
.pr-hist-t .muted { font-weight: 400; }
|
| 2697 |
+
.pr-tab { width: 100%; border-collapse: collapse; font-size: 12px; }
|
| 2698 |
+
.pr-tab td { padding: 2px 6px 2px 0; border: 0; text-align: left; white-space: nowrap; }
|
| 2699 |
+
.pr-tab tr.pr-enc td { color: var(--tinta-3); }
|
| 2700 |
+
.pr-mais { font-size: 11px; margin-top: 4px; }
|
| 2701 |
+
|
| 2702 |
+
/* Quem tem: botao Historico e o grafico que abre embaixo da linha (18/11/2026). */
|
| 2703 |
+
.btn-hist { font: inherit; font-size: 11.5px; padding: 2px 8px; cursor: pointer; white-space: nowrap;
|
| 2704 |
+
background: none; color: var(--tinta-2); border: 1px solid var(--regua); border-radius: 3px; }
|
| 2705 |
+
.btn-hist:hover, .btn-hist.on { color: var(--tinta); border-color: var(--teal); }
|
| 2706 |
+
tr.hist-linha > td { padding: 6px 0 14px; background: var(--papel-2); }
|
| 2707 |
+
/* O grafico fica PRESO a esquerda da rolagem lateral da tabela, com a largura
|
| 2708 |
+
da tela: sem isso, no celular ele teria a largura da tabela inteira. */
|
| 2709 |
+
.hist-caixa { position: sticky; left: 0; width: min(100%, calc(100vw - 48px)); max-width: 860px; padding: 0 10px; }
|
| 2710 |
+
.hist-tit { font-size: 12.5px; margin: 2px 0 6px; }
|
| 2711 |
+
.chart.chart-hist { height: 280px; }
|